Click here to Skip to main content
12,633,417 members (30,539 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

9.4K views
2 bookmarked
Posted

Serialize DependencyObject : it's easy !

, 25 Feb 2010 CPOL
Rate this:
Please Sign up or sign in to vote.
You often read on the web that the DependencyObjects are not marked as serializable and that this is a major drawback of them...But there is a easy way to perform a serialization of these object : use XAMLWriter and XAMLReader :public class MyDependencyObject : DependencyObject{public...
You often read on the web that the DependencyObjects are not marked as serializable and that this is a major drawback of them...

But there is a easy way to perform a serialization of these object : use XAMLWriter and XAMLReader :
public class MyDependencyObject : DependencyObject
{
public static readonly DependencyProperty MyDependencyPropertyProperty =
  DependencyProperty.Register("MyDependencyProperty", typeof(String), typeof(MyDependencyObject));
 
  public String MyDependencyProperty
  {
    get { return (String)GetValue(MyDependencyObject.MyDependencyPropertyProperty); }
    set { SetValue(MyDependencyObject.MyDependencyPropertyProperty, value); }
  }
 
}
 
...
 
MyDependencyObject obj = new MyDependencyObject();
obj.MyDependencyProperty = "One love";
String serializedString = XamlWriter.Save(obj);
Console.WriteLine(serializedString);


It will produce something like this :
<MyDependencyObject MyDependencyProperty="One love" xmlns="clr-namespace:ANTOINE.Jonathan;assembly=ANTOINE.Jonathan" /> :)

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

jmix90
Software Developer http://wpf-france.fr
France (Metropolitan) France (Metropolitan)
Jonathan creates software, mostly with C#,WPF and XAML.

He really likes to works on every Natural User Interfaces(NUI : multitouch, touchless, etc...) issues.



He is awarded Microsoft MVP in the "Client Application Development" section since 2011.


You can check out his WPF/C#/NUI/3D blog http://www.jonathanantoine.com.

He is also the creator of the WPF French community web site : http://wpf-france.fr.

Here is some videos of the projects he has already work on :

You may also be interested in...

Pro
Pro

Comments and Discussions

 
GeneralReason for my vote of 2 useless Pin
jason_999923-Nov-10 2:17
memberjason_999923-Nov-10 2:17 
GeneralReason for my vote of 5 ok Pin
caongocnam29-Jun-10 3:54
membercaongocnam29-Jun-10 3:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.161208.2 | Last Updated 25 Feb 2010
Article Copyright 2010 by jmix90
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid