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

Is there a way to persist Custom RadtreeView

5 Answers 128 Views
PersistenceFramework
This is a migrated thread and some comments may be shown as answers.
Prabakaran
Top achievements
Rank 1
Prabakaran asked on 06 Nov 2015, 11:11 AM

Dear Team,

I want to persist radtreeview state. How can i achieve this behavior. Here is my custom XAML code. please help to advise.

 

<telerik:RadTreeView Margin="8"
                                                    x:Name="xTreeView"
                                                    ItemsSource="{Binding Categories,Mode=TwoWay}"
                                                    IsLineEnabled="True"
                                                    telerik:TreeViewSettings.DragDropExecutionMode="Legacy"
                                                    mouse:MouseDoubleClick.Command="{Binding ShowItemCommand}"
                                                    mouse:MouseDoubleClick.CommandParameter="{Binding   ElementName=xTreeView,Path=SelectedItem}"
                                                    ScrollViewer.VerticalScrollBarVisibility="Visible"
                                                    ScrollViewer.HorizontalScrollBarVisibility="Visible"
                                                    IsDragDropEnabled="True"
                                                    AllowDrop="True"
                                                    telerik:PersistenceManager.StorageId="treeViewInfotab">
                                   <telerik:RadTreeView.ItemTemplate>
                                       <HierarchicalDataTemplate>
                                           <StackPanel Orientation="Horizontal">
                                               <CheckBox IsChecked="{Binding IsChecked, Mode=TwoWay}"
                                                         telerik:StyleManager.Theme="Office_Black" />
                                               <TextBlock VerticalAlignment="Center"
                                                          Text="{Binding Name}" />
                                               <TextBlock Text="{Binding InfoTabItemsSourcePath}"
                                                          Visibility="Hidden" />
                                           </StackPanel>
                                       </HierarchicalDataTemplate>
                                   </telerik:RadTreeView.ItemTemplate>
                               </telerik:RadTreeView>
 

Thank you.

Regards,

Prabakaran

5 Answers, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 10 Nov 2015, 11:27 AM
Hello Prabakaran,

You can persist the treeview's visual state using the approach demonstrated in the Getting Started or Isolated Storage help article in the PersistenceFramework's documentation. However, keep in mind that the framework is saving only primitive type properties and collections of primitive type values (string, int, double, bool, etc.). Any other objects, as ItemsSource and DataTemplates won't be persisted. To avoid losing the control's defined data templates when its deserialized with the persistence framework, you can rest them after the load process. Or you can use serialization options to disable their serialization.

To persist complex objects you can create a custom property provider and implement logic for their serialization. You can find such examples in our SDK GitHub repostiroy.

Also, all bindings should be defined with Mode set to TwoWay. Otherwise, they might not be serialized as expected.

Please let me know if this information is useful.

Regards,
Martin
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Prabakaran
Top achievements
Rank 1
answered on 12 Nov 2015, 01:23 AM

Dear Martin,

As you highlighted, ItemsSource cannot be persisted. you mean there is no way to persist the treeview if we are using itemsource with custom model object as the datatype? our application should satisfy dynamic binding to radtreeview and i need to go with itemsource option. please advise, is there any way i can acheive this? please refer my previous post code for my implementation.

Thank you.

Regards,

Prabakaran

0
Martin Ivanov
Telerik team
answered on 16 Nov 2015, 11:58 AM
Hello Prabakaran,

Note that the persistence manager is saving only the UI of the container and not its data source. In order to save the ItemsSource of RadTreeView you can store the collection in a file or a database, or in memory - it depends on your scenario. However, the manager will save automatically the treeview's bindings and restore them when you load the treeview control. So, in other words if you have the collection that serves as an ItemsSource of RadTreeView, when the persistence loads the control, the ItemsSource binding will be applied. Keep in mind that only TwoWay bindings will be saved.

As a side note, you should be able to persist the ItemsSource with the persistence manager but this will require relatively complex implementation and I do not recommended it.

Regards,
Martin
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Prabakaran
Top achievements
Rank 1
answered on 17 Nov 2015, 01:37 AM

Dear Martin,

Thanks for your reply, do you have TreeviewCustomPropertyProvider class. Please share it, it will helpful for me to use since i am binding custom data source to treeview, in order to save and load the respective parent/child items with drag and drop position.

Thank you.

Regards,

Prabakaran

0
Martin Ivanov
Telerik team
answered on 18 Nov 2015, 11:50 AM
Hello Prabakaran,

I do not have a custom property provider that saves specific properties of RadTreeView. However, keep in mind that I recommend you to use another approach for saving your data - database, in memory or in a file for example. As for the drag and drop saving/loading you can check the Drag and Drop help article and section in our help documentation. There you can find several helpful scenarios which might be useful for your case.

Regards,
Martin
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
PersistenceFramework
Asked by
Prabakaran
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Prabakaran
Top achievements
Rank 1
Share this question
or