XML serialization and cloning...

In message http://groups.google.com/group/microsoft.public.windows.developer.winfx.avalon/msg/f385306eb9c073a8

Nick Kramer discusses some options wrt serializing Visuals to XAML. He mentions various callbacks that might enable serialization of events, but I cant seem to find these callbacks in recent versions of the framework.

Elsewhere in these groups, others have suggested that serializing to XAML and back again is a good way to clone a Visual or FrameworkElement.

Im working on an application where I want to enable cloning controls with all properties and bindings intact. Does anyone have any suggestions as to how I might go about this



Answer this question

XML serialization and cloning...

  • timeee

    hi,

    Im working on an application where I want to enable cloning controls with all properties and bindings, and events intact. Does anyone have any suggestions as to how I might go about this

    how can i save the contorl (other than using xamlwriter.save() ), and finally how can i load the save contol information into anew window or page.

    thanks prasanth


  • Foxabilo

    It's not fully functional in the February CTP, but the idea is that you can use MarkupObject and MarkupWriter to do advanced serialization stuff. (Almost all all of it is there, but we found out shortly after we finished the February CTP that we were missing one critical method, how to get a MarkupObject for a given object to be serialized)

    Idea is that serialization has two layers. The high-level is XamlWriter.Saved(), which takes in object and spits out xaml. It's good for simple stuff, but most people don't want to do very simple stuff (even if they don't realize it <g>), for all the reasons previously discussed.

    The lower layer, on top of which XamlWriter.Save() is built, is MarkupObject & friends. Basically, MarkupObject looks at the object you give it, and tells you "here are the five properties you should serialize" and lets you generate the appropriate XML. MarkupObject looks at the object's associated TypeDescriptor, which like WinForms can be used to customize which properties should be serialized.



  • Apsis

    See an example of using MarkupObject and MarkupProperty here:

    http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=718928&SiteID=1&mode=1

    Thanks, Rob Relyea
    Program Manager, WPF Team
    http://rrelyea.spaces.live.com


  • Dhinesh

    Rob,

    Is there any examples of creating your own MarkupObject for a custom type you've created This way I can build my own xaml when XamlWriter.Save is called on the object correct

    Any XamlWriter (Microsoft.Samples.XamlWriter or the framework provided XamlWriter would just get the Xaml from my MarkupObject correct



  • XML serialization and cloning...