How can I serialize Color type?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dmitry Nogin

    #1

    How can I serialize Color type?

    Hi,

    Can I xml serialize the property of type Color?

    The following doesn't work:

    [TypeConverter(t ypeof(ColorConv erter))]
    [XmlElement(type of(string))]
    public Color TextColor
    { get; set; }

    How?

    -- thanks


  • Dmitry Nogin

    #2
    Re: How can I serialize Color type?

    "Dmitry Nogin" <dmitrynogin@ho tmail.comwrote in message
    news:%23csweF73 HHA.5160@TK2MSF TNGP05.phx.gbl. ..
    Can I xml serialize the property of type Color?
    OK, I did it. Looks ugly...
    private Color _textColor = SystemColors.Wi ndowText;

    [DisplayName("Te xt Color")]
    [XmlIgnoreAttrib ute()]
    public Color TextColor
    {
    get { return _textColor; }
    set { _textColor = value; }
    }

    [XmlElement("Tex tColor")]
    [Browsable(false )]
    public string TextColorHtml
    {
    get { return ColorTranslator .ToHtml(_textCo lor); }
    set { _textColor = ColorTranslator .FromHtml(value ); }
    }






    Comment

    • John Saunders [MVP]

      #3
      Re: How can I serialize Color type?

      "Dmitry Nogin" <dmitrynogin@ho tmail.comwrote in message
      news:%23csweF73 HHA.5160@TK2MSF TNGP05.phx.gbl. ..
      Hi,
      >
      Can I xml serialize the property of type Color?
      >
      The following doesn't work:
      >
      [TypeConverter(t ypeof(ColorConv erter))]
      [XmlElement(type of(string))]
      public Color TextColor
      { get; set; }
      What happens if you remove the two attributes?
      --
      John Saunders [MVP]

      Comment

      Working...