This is a migrated thread and some comments may be shown as answers.

Saving/Restoring TreeView with custom items in heirarchy

2 Answers 78 Views
PersistenceFramework
This is a migrated thread and some comments may be shown as answers.
Scott
Top achievements
Rank 1
Scott asked on 26 Sep 2011, 11:13 PM
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>

2 Answers, 1 is accepted

Sort by
0
Accepted
Alex Fidanov
Telerik team
answered on 29 Sep 2011, 04:49 PM
Hello Scott,

The PersistenceFramework works only with FrameworkElements and their properties. As you have bound the treeview control, its Items collection holds your business objects rather than the treeviewitem containers. That is why, the settings of the items is not persisted.

You could implement an ICustomPropertyProvider and save the state of the business objects - for example the IsSelected, IsChecked (CheckState), IsExpanded properties, etc., that you have bound with ContainerBinding. When loading, you would have to match the saved objects with the ones in the ItemsSource, so I would recommend using an identifier (much like the GridView persisting demo and the GridViewColumns).

Please let me know if you have questions on this or if you need further assistance.

Kind regards,
Alex Fidanov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Scott
Top achievements
Rank 1
answered on 29 Sep 2011, 05:26 PM
Thanks for the confirmation. That is what I thought the answer was going to be.
Tags
PersistenceFramework
Asked by
Scott
Top achievements
Rank 1
Answers by
Alex Fidanov
Telerik team
Scott
Top achievements
Rank 1
Share this question
or