I have created a custom collection class that I am trying to bind to two different treeviews in silverlight. The collection implements INotifyCollectionChanged and the type that the collection holds implements INotifyPropertyChanged. On the GUI is a DataGrid that sits between the two treeviews. This is an area where items can be dragged from the left treeview and manipulated. The changes are then reflected in the second treeview. The first treeview should only bind once and the second treeview should update whenever there is a change to the source. For some reason, however, OneTime binding on the first treeview doesn’t seem to work at all; the treeview still gets updated. Will OneTime binding work if a type implements INotifyCollectionChanged or INotifyPropertyChanged? The markup for the treeview that isn’t working correctly looks similar to this. I’ve removed a few details that are irrelevant to the issue. The DataContext of the treeview is set to a type called Client, for example, _tv.DataContext = client. Each client has a collection of plans and each plan in turn has a collection of allocations. I’m using a HierarchicalDataTemplate for the treeviews. Am I overlooking something? The INotifyPropertyChanged and INotifyCollectionChanged is implemented correctly. I don’t think it’s a logic issue.
<sdk:TreeView Name="_tv" ItemsSource="{Binding Plans, Mode=OneTime}">
<sdk:TreeView.ItemTemplate>
<sdk:HierarchicalDataTemplate ItemsSource="{Binding Allocations, Mode=OneTime}">
<TextBlock Text="{Binding Name, Mode=OneTime}"/>
<sdk:HierarchicalDataTemplate.ItemTemplate>
<DataTemplate>
<TextBlock>
<Run Text="{Binding Fund.Allocations.Count}"></Run>
<Run Text="{Binding Fund.Symbol}"></Run>
<Run Text="{Binding Fund.Name}"></Run>
<Run Text="{Binding Fund.AssetClass}"></Run>
</TextBlock>
</DataTemplate>
</sdk:HierarchicalDataTemplate.ItemTemplate>
</sdk:HierarchicalDataTemplate>
</sdk:TreeView.ItemTemplate>
</sdk:TreeView>
The binding to
Plansisn’t actually changing, sincePlansisn’t actually changing. It is the contents ofPlansthat is changing, and thus theOneTimeinstruction won’t suppress the display of those changes.