Here is some XAML
<HierarchicalDataTemplate DataType="{x:Type data:FolderEntity}"
ItemsSource="{Binding Path=FolderEntities,UpdateSourceTrigger=PropertyChanged}">
<Label Content="{Binding FolderName}"/>
</HierarchicalDataTemplate>
<TreeView/>
data:FolderEntity is a LINQ to SQL data class which implements the INotifyPropertyChanging and INotifyPropertyChanged interfaces.
My problem is that when I change the FolderEntities property the binding doesn't update. If I change the FolderName property the tree node that corresponds to that item will change, but the collection that is FolderEntities just wont.
I'm thinking WPF checks to see whether the collection reference has changed, or does the ItemsSource object have to be an ObservableCollection`1 for this to work?
Any input on the matter is much appreciated.
Yes, the underlying collection (FolderEntities) will need to be an
ObservableCollection<T>
for the HierarchicalDataTemplate to be notified of the changes. Either that or a collection that implements INotifyCollectionChanged.This is how I got it to work, thanks Matt!
Then I specialize that base class to whatever data class I'm currently using.
Slightly modified XAML and it works just great! Changes to the collection or properties of Current updates the TreeView accordingly.
Matt is correct. For the data binding engine to be notified of a change within a collection it need to bind to an ObservableCollection.
What you were binding to was the property and PropertyChanged (from INotifyPropertyChanged) was only being called when the property was being set e.g.
FolderEntities = aNewValue;
the binding engine was unaware of any changes that occurred within the collection.