inherit style from default style

2019-01-07 22:05发布

In my project there is a custom style for text box. It is defined as:

<Style TargetType="TextBox"/>

So it is applied to all text box child controls by default.

I need to create another style that is based on default style. But how do I specify in the BasedOn attribute that my new style should use the default style?

标签: wpf xaml styling
1条回答
ゆ 、 Hurt°
2楼-- · 2019-01-07 22:44

Use the type of the control you would like to extend

BasedOn="{StaticResource {x:Type TextBox}}"

Full example:

<Style x:Key="NamedStyle" TargetType="TextBox" BasedOn="{StaticResource {x:Type TextBox}}">
    <Setter property="Opacity" value="0.5" />
</Style>
查看更多
登录 后发表回答