Is there a way to persist Custom RadtreeView

6 posts, 0 answers
  1. Prabakaran
    Prabakaran avatar
    14 posts
    Member since:
    Feb 2015

    Posted 06 Nov 2015 Link to this post

    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

  2. Martin
    Admin
    Martin avatar
    1101 posts

    Posted 10 Nov 2015 Link to this post

    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
  3. UI for WPF is Visual Studio 2017 Ready
  4. Prabakaran
    Prabakaran avatar
    14 posts
    Member since:
    Feb 2015

    Posted 11 Nov 2015 in reply to Martin Link to this post

    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

  5. Martin
    Admin
    Martin avatar
    1101 posts

    Posted 16 Nov 2015 Link to this post

    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
  6. Prabakaran
    Prabakaran avatar
    14 posts
    Member since:
    Feb 2015

    Posted 16 Nov 2015 in reply to Martin Link to this post

    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

  7. Martin
    Admin
    Martin avatar
    1101 posts

    Posted 18 Nov 2015 Link to this post

    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
Back to Top
UI for WPF is Visual Studio 2017 Ready