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

PersistenceFramework with ItemsControl

4 Answers 112 Views
PersistenceFramework
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Stavroula
Top achievements
Rank 1
Stavroula asked on 17 Feb 2012, 04:06 PM
Hallo Telerik,

ich would like to know if the PersistenceFramework works with the "ItemsControl". I have an ItemsControl and within this I generate dynamically a collection of items (for example CheckBoxes). This ItemControl is located in a RadWindow. I want the state of the CheckBoxes to be persisted. When the user calls the RadWindow again, then the state of the checkBoxes should be restored (checked or unchecked). Could you please give me a hint, how I could do this?
Thanks!

4 Answers, 1 is accepted

Sort by
0
Tina Stancheva
Telerik team
answered on 22 Feb 2012, 02:57 PM
Hi Stavroula,

You can implement your scenario either saving the ItemsControl settings in a stream or in an IsolatedStorage. You can even specify serializaiton options following the approach described in this tutorial. You can also examine this demo solution as it can also help.

I attached a sample project where I saved the setting only of the ItemsControl in an IsolatedStorage - I save the settings when the window is closed and load them when the window is loaded. Please have a look at the solution and let me know how it goes.

Kind regards,
Tina Stancheva
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
Stavroula
Top achievements
Rank 1
answered on 23 Feb 2012, 03:05 PM
Hallo Telerik,

Thank you very much for the example. I have taken your example and I altered the code to fit it to my needs. I found out, that the reason it doesn't work is the <DataTemplate/> in the <ItemsControl/>. I have defined a <DataTemplate/> with a CheckBox within it. The Content- and the IsChecked-Property of the CheckBox are bound (with {Binding...}) to Properties in a MVVM. Should I submit a support ticket to send you my code?

I would appreciate any further suggestion.

Thank you! 
0
Accepted
Tina Stancheva
Telerik team
answered on 28 Feb 2012, 09:52 AM
Hello Stavroula,

The PersistenceManager can persist properties of the following types:
  • Primitive Types
  • UIElement
  • IEnumerable<UIElement>

This means that the framework only persists the visual state of your application. However in a databinding scenario like in your case, the ItemsSource and Items collections cannot be persisted as they contain business objects. This is why in a databinding scenario it isn't recommended to use the PersistenceFramework. It's better to save the updated business objects instead so that you can reload them afterwards.

However, if you still prefer using the PersistanceFramework you can create a custom property provider for the ItemsControl and persist the ItemsSource collection and the business objects properties. I attached a sample project demonstrating this approach. I hope that will help you implement your scenario.

All the best,
Tina Stancheva
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
Stavroula
Top achievements
Rank 1
answered on 29 Feb 2012, 10:44 AM
Hallo Telerik,

thank you very much for the answer. This is exactly what I have been looking for.

Kind regards!
Tags
PersistenceFramework
Asked by
Stavroula
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Stavroula
Top achievements
Rank 1
Share this question
or