从默认样式继承样式

Bog*_*ets 29 wpf xaml styling

在我的项目中,有一个自定义样式的文本框.它被定义为:

<Style TargetType="TextBox"/>
Run Code Online (Sandbox Code Playgroud)

因此,它默认应用于所有文本框子控件.

我需要创建另一种基于默认样式的样式.但是如何在BasedOn属性中指定我的新样式应该使用默认样式?

Aph*_*ion 66

使用您要扩展的控件的类型

BasedOn="{StaticResource {x:Type TextBox}}"
Run Code Online (Sandbox Code Playgroud)

完整示例:

<Style x:Key="NamedStyle" TargetType="TextBox" BasedOn="{StaticResource {x:Type TextBox}}">
    <Setter property="Opacity" value="0.5" />
</Style>
Run Code Online (Sandbox Code Playgroud)