Search code examples
c#windows-runtimewindows-store-appswinrt-xaml

Serialize contents of a Canvas


In a WPF program, I can use System.Windows.Markup.XamlWriter to serialize the contents of a WPF Canvas into text. But this is not available in a windows store/metro app, how then would be able to serialize the contents of a Windows-Store Canvas ?


(My app is similar to a painting application, where the user can draw using a mouse. The 'drawings' are UIElements like Line and Ellipse added as children of a Canvas. I'm looking for a serialization method as I want to be able to save/restore these UIElements).


Solution

  • Since there is no System.Windows.Markup.XamlWriter in either windows store apps or UWP apps, I ended up using Sharp Serializer. It's quite easy to use in both WPF and Windows RT.

    Some other popular serializing engines, from this blog (Choosing the right serialization engine for your Windows Store app), are XmlSerializer, DataContractSerializer, and JsonSerializer.