C # user control property: cannot set DefaultValue field

I am trying to set my own C # control property.

Here is my code:

/* Cancel button text */ [Category("ComboTouch"), Description("Text to display in cancel button"), DefaultValue("Cancel")] public String ct_cancelButtonText { get; set; } 

I can get the property when I use a custom control in other projects (as you can see in the image); but the DefaultValue configuration parameter does not seem to work.

Can someone help me? Thank you very much.

Custom control properties

10/01/13 Update. Thank you very much for your answers, you have solved my problem.

I would like to share how I can finally set the default value automatically:

  private String m_cancelButtonText="Cancel"; /* Cancel button text */ [Category("ComboTouch"), Description("Text to display in cancel button"), DefaultValue("Cancel")] public String ct_cancelButtonText { get { return m_cancelButtonText; } set { m_cancelButtonText = value; } } 

One curiosity: check the "Cancel" text format. If I set the type to DefaultValue; it looks like plain text. But if I do not, it looks like bold text . I know this is stupid; but I would like to know why this is so. Thanks.

enter image description here

+4
source share
1 answer

As stated in the documentation :

A DefaultValueAttribute will not cause the element to be automatically initialized with the attribute value. You must set the initial value in your code.

+4
source

All Articles