Design-time support for CF Control - Declaring a Color default val

G

Guest

Hello.

I am developing a control for the CF 2.0 and I am trying to provide design
time support, using an xmta file to build the metadata assembly. I am trying
to declare the DefaultValue attribute for a property of the
System.Drawing.Color type and I was wondering what the correct syntax is.

For example, I have tried:

<Property Name="ColorfullProperty">
<DefaultValue>
<Type>System.Drawing.Color, System.Drawing, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089</Type>
<Value>Red</Value>
</DefaultValue>
...
</Property>

but it doesnt seem won't work. I have the same problem with many other
properties which are not of the frameworks' native types. All the native type
property declarations work just fine.

Can anyone help? I am Also looking for extensive documentation and examples
on declaring designer attributes using xmta files.

Thank you!
 
J

Jeremy

In my custom controls I don't bother setting default colors in the
XMTA file. I just set the private Color variables when they are
declared and that works fine for me.
 
G

Guest

I do set the default values in my control's constructor, but I also wish
avoid the extra code generated by the designer for these properties.

Thanks for replying!
 
J

Jeremy

try this, this little sample shows the use of ShouldSerializeXXX and
ResetXXX methods

ShouldSerializeXXX will prevent extra auto generated code from being
written

ResetXXX will let you "reset" the default color by right clicking the
BGColor property in the VS properties panel and choosing Reset when
you use the control in a project

Just replace "XXX" with the name of the property it's to be connected
to and that should do it. You can repeat this for any other properties
you need to prevent serialization for or you want a reset feature for.



public class MyControl
{
//I find I don't need an XMTA entry for default values when I do
this
private Color _bgColor = Color.Red;

public MyControl()
{
}

public Color BGColor
{
get
{
return(this._bgColor);
}
set
{
this._bgColor = value;
//trigger a redrawing of the control
this.Invalidate();
}
}

//do not serialize the color to auto generated code if it's red
private bool ShouldSerializeBGColor()
{
return(this._bgColor != Color.Red);
}

//reset the property to red
private void ResetBGColor()
{
this._bgColor = Color.Red;
}
}
 

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