I have a TreeView that is using a HierarchicalDataTemplate and ContainerBindingCollection. These use a class I created to display the items in the TreeView. I'm saving the stream of the TreeView to a database. Whn I restore the TreeView I am not getting any items expanded or checked. When I do the same with TreeViewItems declared in the TreeView itesself (in XAML) ir works fine. Do I need to use a custom ICustomPropertyProvider to do this?
My TreeView style:
<Style x:Key="RadTreeViewSelectExpandedStyle" TargetType="telerik:RadTreeView" BasedOn="{StaticResource RadTreeViewStyleBase}">
<Setter Property="IsOptionElementsEnabled" Value="True"/>
<Setter Property="IsTriStateMode" Value="True" />
<Setter Property="ItemTemplate">
<Setter.Value>
<telerik:HierarchicalDataTemplate ItemsSource="{Binding Children}" telerik:ContainerBinding.ContainerBindings="{StaticResource TreeViewItemCheckedExpandedBindingCollection}">
<TextBlock Text="{Binding Value}" />
</telerik:HierarchicalDataTemplate>
</Setter.Value>
</Setter>
</Style>
My ContainerBindingCollection
<telerik:ContainerBindingCollection x:Key="TreeViewItemCheckedExpandedBindingCollection">
<telerik:ContainerBinding Binding="{Binding Path=CheckState, Mode=TwoWay}" PropertyName="CheckState" />
<telerik:ContainerBinding Binding="{Binding Path=Expanded, Mode=TwoWay}" PropertyName="IsExpanded" />
</telerik:ContainerBindingCollection>
My TreeView style:
<Style x:Key="RadTreeViewSelectExpandedStyle" TargetType="telerik:RadTreeView" BasedOn="{StaticResource RadTreeViewStyleBase}">
<Setter Property="IsOptionElementsEnabled" Value="True"/>
<Setter Property="IsTriStateMode" Value="True" />
<Setter Property="ItemTemplate">
<Setter.Value>
<telerik:HierarchicalDataTemplate ItemsSource="{Binding Children}" telerik:ContainerBinding.ContainerBindings="{StaticResource TreeViewItemCheckedExpandedBindingCollection}">
<TextBlock Text="{Binding Value}" />
</telerik:HierarchicalDataTemplate>
</Setter.Value>
</Setter>
</Style>
My ContainerBindingCollection
<telerik:ContainerBindingCollection x:Key="TreeViewItemCheckedExpandedBindingCollection">
<telerik:ContainerBinding Binding="{Binding Path=CheckState, Mode=TwoWay}" PropertyName="CheckState" />
<telerik:ContainerBinding Binding="{Binding Path=Expanded, Mode=TwoWay}" PropertyName="IsExpanded" />
</telerik:ContainerBindingCollection>