比如说,我有一个TextBox“TextBoxStyleBase”的默认样式。然后,我定义一个DataGrid样式,该样式具有TextBox基于该基本样式的自己的样式,并定义另一个边框颜色。
在 a 内部的某个地方,DataGrid我想定义另一种TextBox样式,但继承于 style 中定义的样式DataGrid。
有没有办法使样式继承当前为当前“上下文”中的特定控件定义的样式?
编辑:
为了更清楚地说明,这是我所拥有的:
<!-- explicit style for all TextBoxes -->
<Style TargetType="{x:Type TextBox}" x:Key="TextStyle">
<Setter Property="FontSize" Value="16"/>
</Style>
<!-- implicit style for all TextBoxes -->
<Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource TextStyle}"/>
<!-- DataGrid style changing inner TextBox style -->
<Style TargetType="{x:Type DataGrid}">
<Style.Resources>
<Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource TextStyle}">
<Setter Property="FontSize" Value="20"/>
</Style>
<!-- since TextBox has defined implicit style this would be equivalent …Run Code Online (Sandbox Code Playgroud)