This question is locked. New answers and comments are not allowed.
Hi,
I am somehow struggling with this treeview for quite sometime now.. I am trying to bind a list to the ItemsSource property of the Treeview. But it never returns data. Please note that I want the treeview to be populated only on click of a button and not during page load. Please find below the CS and XAML code. Please let me know what am doing wrong here
| using System; | |||||||||||||||||||||||||||||||||||||||
| using System.Collections.Generic; | |||||||||||||||||||||||||||||||||||||||
| using System.Linq; | |||||||||||||||||||||||||||||||||||||||
| using System.Net; | |||||||||||||||||||||||||||||||||||||||
| using System.Windows; | |||||||||||||||||||||||||||||||||||||||
| using System.Windows.Controls; | |||||||||||||||||||||||||||||||||||||||
| using System.Windows.Documents; | |||||||||||||||||||||||||||||||||||||||
| using System.Windows.Input; | |||||||||||||||||||||||||||||||||||||||
| using System.Windows.Media; | |||||||||||||||||||||||||||||||||||||||
| using System.Windows.Media.Animation; | |||||||||||||||||||||||||||||||||||||||
| using System.Windows.Shapes; | |||||||||||||||||||||||||||||||||||||||
| using Telerik.Windows.Controls.DragDrop; | |||||||||||||||||||||||||||||||||||||||
| using System.Collections.ObjectModel; | |||||||||||||||||||||||||||||||||||||||
| using System.ComponentModel; | |||||||||||||||||||||||||||||||||||||||
| namespace SilverlightApplication2 | |||||||||||||||||||||||||||||||||||||||
| { | |||||||||||||||||||||||||||||||||||||||
| public partial class MainPage : UserControl,INotifyPropertyChanged | |||||||||||||||||||||||||||||||||||||||
| { | |||||||||||||||||||||||||||||||||||||||
| private List<ProvHeader> treeDataSource; | |||||||||||||||||||||||||||||||||||||||
| // Declare the PropertyChanged event | |||||||||||||||||||||||||||||||||||||||
| public event PropertyChangedEventHandler PropertyChanged; | |||||||||||||||||||||||||||||||||||||||
| public List<ProvHeader> TreeDataSource | |||||||||||||||||||||||||||||||||||||||
| { | |||||||||||||||||||||||||||||||||||||||
| get { return this.treeDataSource; } | |||||||||||||||||||||||||||||||||||||||
| set | |||||||||||||||||||||||||||||||||||||||
| { | |||||||||||||||||||||||||||||||||||||||
| if (this.treeDataSource == value) | |||||||||||||||||||||||||||||||||||||||
| return; | |||||||||||||||||||||||||||||||||||||||
| this.treeDataSource = value; | |||||||||||||||||||||||||||||||||||||||
| this.OnPropertyChanged(new PropertyChangedEventArgs("TreeDataSource")); | |||||||||||||||||||||||||||||||||||||||
| } | |||||||||||||||||||||||||||||||||||||||
| } | |||||||||||||||||||||||||||||||||||||||
| public MainPage() | |||||||||||||||||||||||||||||||||||||||
| { | |||||||||||||||||||||||||||||||||||||||
| InitializeComponent(); | |||||||||||||||||||||||||||||||||||||||
| } | |||||||||||||||||||||||||||||||||||||||
| // NotifyPropertyChanged will raise the PropertyChanged event passing the | |||||||||||||||||||||||||||||||||||||||
| // source property that is being updated. | |||||||||||||||||||||||||||||||||||||||
| protected virtual void OnPropertyChanged(PropertyChangedEventArgs e) | |||||||||||||||||||||||||||||||||||||||
| { | |||||||||||||||||||||||||||||||||||||||
| if (this.PropertyChanged != null) | |||||||||||||||||||||||||||||||||||||||
| this.PropertyChanged(this, e); | |||||||||||||||||||||||||||||||||||||||
| } | |||||||||||||||||||||||||||||||||||||||
| private void GetData_Click(object sender, RoutedEventArgs e) | |||||||||||||||||||||||||||||||||||||||
| { | |||||||||||||||||||||||||||||||||||||||
| List<ProvHeader> pl = new List<ProvHeader>(); | |||||||||||||||||||||||||||||||||||||||
| ProvHeader p; | |||||||||||||||||||||||||||||||||||||||
| PaytoProv p2p; | |||||||||||||||||||||||||||||||||||||||
| Provider child; | |||||||||||||||||||||||||||||||||||||||
| pl.Add(p = new ProvHeader("Manager")); | |||||||||||||||||||||||||||||||||||||||
| p.PaytoProviders.Add(p2p = new PaytoProv("Programmer")); | |||||||||||||||||||||||||||||||||||||||
| p2p.Providers.Add(new Provider("ModuleLead")); | |||||||||||||||||||||||||||||||||||||||
| p2p.Providers.Add(child = new Provider("Test2")); | |||||||||||||||||||||||||||||||||||||||
| p2p.Providers.Add(child = new Provider("Test3")); | |||||||||||||||||||||||||||||||||||||||
| p2p.Providers.Add(child = new Provider("Test4")); | |||||||||||||||||||||||||||||||||||||||
| TreeDataSource = pl; | |||||||||||||||||||||||||||||||||||||||
| //ProviderTreeView.ItemsSource = TreeDataSource; | |||||||||||||||||||||||||||||||||||||||
| } | |||||||||||||||||||||||||||||||||||||||
| } | |||||||||||||||||||||||||||||||||||||||
| public class Provider | |||||||||||||||||||||||||||||||||||||||
| { | |||||||||||||||||||||||||||||||||||||||
| public Provider(string name) | |||||||||||||||||||||||||||||||||||||||
| { | |||||||||||||||||||||||||||||||||||||||
| this.Name = name; | |||||||||||||||||||||||||||||||||||||||
| } | |||||||||||||||||||||||||||||||||||||||
| public string Name | |||||||||||||||||||||||||||||||||||||||
| { | |||||||||||||||||||||||||||||||||||||||
| get; | |||||||||||||||||||||||||||||||||||||||
| set; | |||||||||||||||||||||||||||||||||||||||
| } | |||||||||||||||||||||||||||||||||||||||
| } | |||||||||||||||||||||||||||||||||||||||
| public class PaytoProv | |||||||||||||||||||||||||||||||||||||||
| { | |||||||||||||||||||||||||||||||||||||||
| public PaytoProv(string name) | |||||||||||||||||||||||||||||||||||||||
| { | |||||||||||||||||||||||||||||||||||||||
| this.Name = name; | |||||||||||||||||||||||||||||||||||||||
| this.Providers = new List<Provider>(); | |||||||||||||||||||||||||||||||||||||||
| } | |||||||||||||||||||||||||||||||||||||||
| public string Name | |||||||||||||||||||||||||||||||||||||||
| { | |||||||||||||||||||||||||||||||||||||||
| get; | |||||||||||||||||||||||||||||||||||||||
| set ; | |||||||||||||||||||||||||||||||||||||||
| } | |||||||||||||||||||||||||||||||||||||||
| public List<Provider> Providers | |||||||||||||||||||||||||||||||||||||||
| { | |||||||||||||||||||||||||||||||||||||||
| get; | |||||||||||||||||||||||||||||||||||||||
| set; | |||||||||||||||||||||||||||||||||||||||
| } | |||||||||||||||||||||||||||||||||||||||
| } | |||||||||||||||||||||||||||||||||||||||
| public class ProvHeader | |||||||||||||||||||||||||||||||||||||||
| { | |||||||||||||||||||||||||||||||||||||||
| public ProvHeader(string name) | |||||||||||||||||||||||||||||||||||||||
| { | |||||||||||||||||||||||||||||||||||||||
| this.Name = name; | |||||||||||||||||||||||||||||||||||||||
| this.PaytoProviders = new List<PaytoProv>(); | |||||||||||||||||||||||||||||||||||||||
| } | |||||||||||||||||||||||||||||||||||||||
| public string Name | |||||||||||||||||||||||||||||||||||||||
| { | |||||||||||||||||||||||||||||||||||||||
| get; | |||||||||||||||||||||||||||||||||||||||
| set; | |||||||||||||||||||||||||||||||||||||||
| } | |||||||||||||||||||||||||||||||||||||||
| public List<PaytoProv> PaytoProviders | |||||||||||||||||||||||||||||||||||||||
| { | |||||||||||||||||||||||||||||||||||||||
| get; | |||||||||||||||||||||||||||||||||||||||
| set; | |||||||||||||||||||||||||||||||||||||||
| } | |||||||||||||||||||||||||||||||||||||||
| } | |||||||||||||||||||||||||||||||||||||||
| } | |||||||||||||||||||||||||||||||||||||||
|