PersistenceFramework with ItemsControl

5 posts, 1 answers
  1. Stavroula
    Stavroula avatar
    5 posts
    Member since:
    Sep 2011

    Posted 17 Feb 2012 Link to this post

    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!
  2. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 22 Feb 2012 Link to this post

    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 >>
  3. DevCraft banner
  4. Stavroula
    Stavroula avatar
    5 posts
    Member since:
    Sep 2011

    Posted 23 Feb 2012 Link to this post

    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! 
  5. Answer
    Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 28 Feb 2012 Link to this post

    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 >>
  6. Stavroula
    Stavroula avatar
    5 posts
    Member since:
    Sep 2011

    Posted 29 Feb 2012 Link to this post

    Hallo Telerik,

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

    Kind regards!
Back to Top
DevCraft banner