locked
Is there a way to serialize my objects to XAML in Windows Store applications? RRS feed

  • Question

  • Is there a way to serialize my objects to XAML in Windows Store applications? I've searched wherever I could, and found nothing... I need something like the methods inside System.Xaml.XamlServices.
    Monday, December 23, 2013 10:48 PM

Answers

  • You'll have to implement it yourself. You'll need to iterate the visual tree to find the controls and then can serialize them with XML classes. The big trick will be determining which properties are essential to set and which can be left for default.

    --Rob

    Tuesday, December 31, 2013 12:52 AM
    Moderator

All replies

  • Hi Shayan,

    If you search for "serialize" in the search box in the top right of the Windows Store apps dev center you'll get hits on .Net serialization classes you can use in your Windows Store app. You can also use the Object Browser inside Visual Studio to find such classes.

    Likewise if you follow the "samples" link in the dev center and search for "serialize" there are a number of samples available.

    --Rob

    Tuesday, December 24, 2013 12:29 AM
    Moderator
  • I know how to serialize an object, I want to serialize to and deserialize from XAML.
    Wednesday, December 25, 2013 11:38 AM
  • What do you mean by serialize to and deserialize from XAML? It would help if you could provide more clear examples of what you are trying to do.

    There is a XamlReader class which can load a Xaml fragment into an object tree. There is no analogous writer, but you can serialize and deserialize your data objects to XML and rebuild a Xaml tree based on that.

    --Rob

    Friday, December 27, 2013 12:17 AM
    Moderator
  • There is a XamlReader class which can load a Xaml fragment into an object tree. There is no analogous writer, but you can serialize and deserialize your data objects to XML and rebuild a Xaml tree based on that.

    Thanks for the XamlReader. But I need exactly that "analogous writer". What do you mean by "rebuild a Xaml tree based on that", exactly? What does "rebuild" means? You mean editing the generated XML? Using what?
    Friday, December 27, 2013 11:52 AM
  • You'll have to implement it yourself. You'll need to iterate the visual tree to find the controls and then can serialize them with XML classes. The big trick will be determining which properties are essential to set and which can be left for default.

    --Rob

    Tuesday, December 31, 2013 12:52 AM
    Moderator