Default value for Color property

S

Stefan Hoffmann

hi @all,

I have a control defining this Color property:

public Color GridColor { get; set; }
public bool ShouldSerializeGridColor()
{
return GridColor != Color.Magenta;
}
public void ResetGridColor()
{
GridColor = Color.Magenta;
}

But it is not displayed in the property editor. How can I apply a
default value to a non simple property?

Also the DefaultValue attribute does not work:

[Category("Appearance"),
Description("Color for grid."),
DefaultValue(GetType(Color), "Color.Red")]
public Color GridColor { get; set; }


mfG
--> stefan <--
 
M

Marc Gravell

[DefaultValueAttribute] only affects whether it believes it is a default
(and even that is overridden in your case). You still need to actually
assign that as the initial value - i.e.

public class MyClass {
// snip metadata
public Color GridColor {get; set;}

pubblic MyClass() {
GridColor = Color.Magenta; // or call ResetGridColor
}

// snip
}

Marc
 
S

Stefan Hoffmann

hi Marc,

Marc said:
[DefaultValueAttribute] only affects whether it believes it is a default
(and even that is overridden in your case). You still need to actually
assign that as the initial value - i.e.
Thanks, this is the solution.

mfG
--> stefan <--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top