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

persisting breadcrumb and treeView

9 Answers 125 Views
PersistenceFramework
This is a migrated thread and some comments may be shown as answers.
Alex
Top achievements
Rank 1
Alex asked on 28 Mar 2012, 02:57 PM
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

9 Answers, 1 is accepted

Sort by
0
Alex Fidanov
Telerik team
answered on 02 Apr 2012, 08:26 AM
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 >>
0
Alex
Top achievements
Rank 1
answered on 03 Apr 2012, 04:15 PM
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"/>

0
Tina Stancheva
Telerik team
answered on 06 Apr 2012, 11:19 AM
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 >>

0
Alex
Top achievements
Rank 1
answered on 13 Apr 2012, 10:30 AM

 

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

0
Tina Stancheva
Telerik team
answered on 17 Apr 2012, 03:50 PM
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 >>

0
Alex
Top achievements
Rank 1
answered on 17 Apr 2012, 04:42 PM
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

 

 

0
Tina Stancheva
Telerik team
answered on 17 Apr 2012, 05:22 PM
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 >>

0
Alex
Top achievements
Rank 1
answered on 17 Apr 2012, 05:35 PM
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! ;(
0
Tina Stancheva
Telerik team
answered on 17 Apr 2012, 06:12 PM
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 >>

Tags
PersistenceFramework
Asked by
Alex
Top achievements
Rank 1
Answers by
Alex Fidanov
Telerik team
Alex
Top achievements
Rank 1
Tina Stancheva
Telerik team
Share this question
or