9 Answers, 1 is accepted
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
<
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"
/>
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 >>
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
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 >>
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
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 >>
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 >>