Setting TreeView.DataContext doesn't refresh the tree
Posted
by dan gibson
on Stack Overflow
See other posts from Stack Overflow
or by dan gibson
Published on 2010-05-31T07:53:58Z
Indexed on
2010/05/31
22:03 UTC
Read the original article
Hit count: 380
wpf
I have a List that I've bound to a TreeView. Setting TreeView.DataContext works - everything displays correctly. I then change the list (add an item to it) and set TreeView.DataContext again (to the same value) but the tree does not refresh with the new items. How do I get the treeview to refresh?
This is basically my code:
public class xItemCollection : ObservableCollection<xItem>
{
}
public class xItem : INotifyPropertyChanged
{
xItemCollection _Items;
public xItem()
{
_Items = new xItemCollection();
}
public xItemCollection Items {get{return _Items;}}
}
...
this.RootItem = new xItem();
treeView.DataContext = this;
Adding items to the list works until the tree is rendered for the first time. After it is rendered, adding/removing items does not refresh the tree.
© Stack Overflow or respective owner