Tuesday, 11 October 2016

XML : How to deserialize string to different data type

I have an XML file with a tag like this:

  <Background>#fff</Background>    

When I deserialize this value I want it to become a SolidBrushColor so I can use it for painting an object. I figured I would do something like the following:

  SolidColorBrush _bg;    public SolidColorBrush BackgroundColor {      get {          return _bg;      }      set {          _bg = new SolidColorBrush(ColorConverter.ConvertFromString(value));      }  }    

But this doesn't work and throws an error at value saying "Cannot convert from SolidColorBrush to string". How do I deserialize the string and make it a different datatype?

No comments:

Post a Comment