开发者

How do you find the default values of controls in XAML?

I have seen that in Blend you can see which properties have been changed and use the reset option to get back to default values.

Is there any other way of finding what the default values of a control are?开发者_Go百科

JD


You can determine the default value of a property by examining the DefaultMetadata property of the static DependencyProperty on the specific class, example:

TextBlock.TextProperty.DefaultMetadata.DefaultValue


Properties in XAML are set to their defaults when they aren't explicitly defined. So Reset in Blend actually just deletes the property from the XAML.

For example, if your control had a Color property:

<MyControl Width="100" Color="Blue"/>

Resetting the color would result in the following:

<MyControl Width="100"/>

This way, Blend doesn't require any knowledge of what a default value is.

For examining what the default values are, this is a little more difficult. The only methods I can think of is to either examine the control using the debugger during runtime, or examining the properties in a control using a tool such as XAMLPad. Documentation on a control may reveal what it's default is as well.


Snoop highlights explicitly set property values at runtime and can give you an idea of the source (e.g. Parent Template).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜