In my previous post I pointed out the most common used Attributes for Design Time Support. In this part I will point out some more Attributes that take advantage of the Design Time Environment.
Attributes | Applied To | Description |
---|---|---|
DisplayName | Properties & Events | Specifies the display name for a property or an event. |
ParenthesizeProperty | Properties | Indicates whether the name of the associated property is displayed with parentheses in the Properties window. |
RefreshProperties | Properties | Indicates that the property grid should refresh when the associated property value changes. |
NotifyParentProperty | Properties | Indicates that the parent property is notified when the value of the property that this attribute is applied to is modified. |
ReadOnly | Properties | Specifies whether the property this attribute is bound to is read-only or read/write. |
DesignOnly | Properties |
Specifies whether a property can only be set at design time. |
[more]
» DisplayNameAttribute is useful when you need the name displayed in the PropertyWindow different than property actual name.
[code:c#]
[DisplayName("Number of Clicks")]
public int NumOfClicks
[/code]
» ParenthesizePropertyAttribute when you have a special property such as Name and need it to appear between brackets this is the attribute to use.
[code:c#]
[ParenthesizePropertyName(true)]
public string SpecialProperty
[/code]
» RefreshPropertiesAttribute when you have property's value which depends on the value of another one then you will need this attribute, mark the property that when changed should refresh others with this attribute.
[code:c#]
[RefreshProperties(RefreshProperties.All)]
public string RefreshOtherProperty
[/code]
» NotifyParentPropertyAttribute Apply this one to a property if its parent property should receive notification of changes to the property's values. For example, the Size property has two nested properties: height and width. These nested properties should be marked with NotifyParentPropertyAttribute(true) so they notify the parent property to update its value and display when the property values change.
[code:c#]
[NotifyParentProperty(true)]
public string NotifyparentProperty
[/code]
» ReadOnlyAttribute When applying this attribute with parameter true then it will be unchangable in the design time, this is different than making a property without a set accessor since properties marked with ReadOnlyAttribute can be changed using code.
[code:c#]
[ReadOnly(true)]
public string ReadOnlyProperty
[/code]
» DesignOnlyAttribute from the name implies that the property marked with this attribute will only be available in the design mode.
[code:c#]
[DesignOnly(true)]
public string DesignTimeOnlyProperty
[/code]
Leave a Reply