persisting breadcrumb and treeView

10 posts, 0 answers
  1. Alex
    Alex avatar
    36 posts
    Member since:
    Sep 2010

    Posted 28 Mar 2012 Link to this post

    I am using breadcrumb example from your demo. I added unique PersistenceManager.StorageId to both controls and saving/loading using Isolated storage provider. It does not seem to work. Any help is much appreciated. Thanks
  2. Alex Fidanov
    Admin
    Alex Fidanov avatar
    636 posts

    Posted 02 Apr 2012 Link to this post

    Hello,

     Which example for the Breadcrumb are you using? Please note that the Persistence Framework is working only with UI elements and containers. In scenario of data bound control, the Items collection contains business objects, which are not being persisted.

    Regards,
    Alex Fidanov
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  3. DevCraft banner
  4. Alex
    Alex avatar
    36 posts
    Member since:
    Sep 2010

    Posted 03 Apr 2012 Link to this post

    I have a ViewModel with Root item as RadTreeViewItem and Items as collection of RadTreeViewItem. If I set pages DataContext to an instance of this model my treeview loads correctly and persistence works (thanks). In the treeview I bind ItemSource to Items, but I am having problem s with loading breadcrumb control. Any idea what am I doing wrong? Thanks
    <telerik:RadBreadcrumb telerik:PersistenceManager.StorageId="Breadcrumb"
                       x:Name="Breadcrumb"
                       Grid.Row="0"
                       CurrentItemChanged="Breadcrumb_CurrentItemChanged"
                       Header="{Binding Root}"
                       HeaderMemberPath="Header"
                       HierarchicalItemsSource="Items"
                       HierarchicalMemberPath="Header"
                       ImagePath="DefaultImageSrc"
                       IsIconVisible="True"
                       IsTextSearchEnabled="True"
                       IsTextModeEnabled="True"
                       ItemsSource="{Binding Root.Items}"
                       TextModePath="Header"/>

  5. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 06 Apr 2012 Link to this post

    Hi Alex,

    I wasn't able to reproduce the issue based on the information you gave us. I created a sample solution using your Breadcrumb definition and I also added a RadTreeView control in the main page of the application. I used the PeristenceFramework to save the RadTreeView and RadBreadcrumb UI settings. And it worked as expected on my side so can you please have a look at the solution and let me know if it works for you or if I'm missing something.

    Thank you in advance.

    Regards,
    Tina Stancheva
    the Telerik team

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

  6. Alex
    Alex avatar
    36 posts
    Member since:
    Sep 2010

    Posted 13 Apr 2012 Link to this post

     

    if I use a Load button it sort of works sometimes in my code. The question is how to load the saved state of the tree automatically on page load? For example

    this.Items = new ObservableCollection<ExplorerItem>() { this.Root };
     
    IsolatedStorageProvider isoProvider = new IsolatedStorageProvider();
    isoProvider.LoadFromStorage();


    The code above does not work. It looks like tree items were not initialised at the time of calling LoadFromStorage(). If click on Load button loads the saved state of the tree
    Thanks

  7. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 17 Apr 2012 Link to this post

    Hi Alex,

    In order to make sure that the RadTreeView is initialized, you can call the LoadFromStorage() method in the Loaded event handler of the UserControl that hosts it, or call it in the Loaded event handler of the RadTreeView control itself.

    However, please keep in mind that the PersistenceFramework can only persist UI properties and when the ItemsSource collection of the RadTreeView/RadTreeViewItem is populated with business items, there won't be RadTreeViewItems in the Items collection of the RadTreeView/RadTreeViewItem. This is why the properties of the children of the databound RadTreeView/RadTreeViewItem can't be persisted using the PersistenceManager and you need to bind them instead.

    Kind regards,
    Tina Stancheva
    the Telerik team

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

  8. Alex
    Alex avatar
    36 posts
    Member since:
    Sep 2010

    Posted 17 Apr 2012 Link to this post

    all contorl are loaded before calling LoadFromStorage()

    In your example add the following 2 lines in MainViewModel at the end after  "this.Items = new ObservableCollection<ExplorerItem>() { this.Root };"
    IsolatedStorageProvider isoProvider = new IsolatedStorageProvider();
    isoProvider.LoadFromStorage();

     

    Now run the project expand the top tree node and then save the state. Stop and run the project again. You will see that the tree will stay the same. Now click "Load" button and the tree should load previously saved state

     

     

  9. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 17 Apr 2012 Link to this post

    Hello Alex,

    When you load the data from the isolated storage while initializing the MainViewModel, the RadTreeView and the MainPage are still not loaded and initialized. This is causing the issue. It is better to load the persisted data in the Loaded event of the UserControl:
    IsolatedStorageProvider isoProvider = new IsolatedStorageProvider();

    public
    MainPage()
    {
        InitializeComponent();
        this.Loaded += new RoutedEventHandler(MainPage_Loaded);
    }
     
    void MainPage_Loaded(object sender, RoutedEventArgs e)
    {
        isoProvider.LoadFromStorage();
    }


    All the best,
    Tina Stancheva
    the Telerik team

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

  10. Alex
    Alex avatar
    36 posts
    Member since:
    Sep 2010

    Posted 17 Apr 2012 Link to this post

    thanks, but I should have said that the problem is when there are 3 levels in the hierarchy. So for example there is Desktop (expand) Computer (expand) Drive C. Select "Drive C" and and save the state. Restart the app and on Load it will not expand "Drive C" item, but clicking on Load button works! ;(
  11. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 17 Apr 2012 Link to this post

    Hi Alex,

    Thank you for getting back to us. This behavior is expected since the first RadTreeViewItem.ItemsSource collection is populated with business items. Let me try to explain why.

    The PersistenceFramework can only save UI properties of UIElements so when saving the layout of an ItemsControl, the framework traverses the Items collection of the control. If the Items collection contains UIElements, the properties of these UIElements are persisted. But if the collection contains business items, the PersistenceFramework can't save their state. In such scenarios, you'll need to use databinding to preserve the sate of the controls.

    In your scenario, the RadTreeView control has one UIElement - its root RadTreeViewItem Desktop. So the RadPersistenceFramework will traverse the Items collection of the RadTreeView and as it contains one UIElement - the root RadTreeViewItem, it will save its properties. Then the framework will try to save the RadTreeViewItem.Items collection but as the ItemsSource of the RadTreeViewItem is populated with business items, so will be the Items collection and the PersistenceFramework won't be able to save the children of the RadTreeViewItem and their properties. Instead, as they are created through data-binding, you can save their state by binding the state-related properties you need to reload later. For example you can use telerik ContainerBindings to bind the IsSelected and IsExpanded properties of the RadTreeView to business objects. And the business objects and collections can be saved in a database so that they can be retrieved when loading the solution.

    Regards,
    Tina Stancheva
    the Telerik team

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

Back to Top
DevCraft banner