My TreeView doesnot updates on adding the element to datasource. I am using this code in xaml
This is the codebehind:
public partial class ProceduresPage : Page, INotifyPropertyChanged {
public ProceduresPage()
{
InitializeComponent();
CustomerSiteTreeDataSource = new ObservableCollection<TreeNodeItem>();
CustomerSiteTreeDataSource.Add(TreeNodeItem newSite= new TreeNodeItem{ Id= "ID", Desc = "Description" });
TV_CustomerSites.DataContext = CustomerSiteTreeDataSource;
}
private ObservableCollection<TreeNodeItem> customerSiteTreeDataSource;
public ObservableCollection<TreeNodeItem> CustomerSiteTreeDataSource
{
get
{
return customerSiteTreeDataSource;
}
set
{
customerSiteTreeDataSource = value;
NotifyPropertyChanged("CustomerSiteTreeDataSource");
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(string property)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(property));
}
}
}
In the addFunction in codebehind
TreeNodeItem newSite= new TreeNodeItem{ Id = "ID", Desc = "Description" };
CustomerSiteTreeDataSource.Add(newSite);
My TreeView binds correctly on load but doesn't updates The UI on adding a new Item to the datasource in the addfunction.
What am I doing wrong?