Wpf 如何将一种样式应用于另一种样式的模板内控件?
我有控制的风格:Wpf 如何将一种样式应用于另一种样式的模板内控件?,wpf,xaml,styles,Wpf,Xaml,Styles,我有控制的风格: <Style x:Key="base style" TargetType="{x:Type cust:SomeCustomControl}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type cust:SomeCustomControl}">
<Style x:Key="base style" TargetType="{x:Type cust:SomeCustomControl}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type cust:SomeCustomControl}">
<DataGrid >
<!-- some content... -->
</DataGrid >
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
我尝试添加另一种样式,它应该与前面的样式完全相同,但在DataGrid的第一行使用“粗体”字体:
<Style x:Key="bold row" TargetType="{x:Type cust:SomeCustomControl}" BasedOn="{StaticResource base style}">
??????????????
??????????????
</Style>
??????????????
??????????????
但我不明白如何在不复制整个“基本样式”代码的情况下更改第一个样式中的某些属性。
我想我应该补充如下内容:
<Style TargetType="{x:Type DataGridCell}">
<Style.Triggers>
<DataTrigger Binding="{Binding RowIndex}" Value="0">
<Setter Property="FontWeight" Value="Bold"/>
</DataTrigger>
</Style.Triggers>
</Style>
但我的“粗体行”样式适用于cust:SomeCustomControl。那么,我如何在“粗体行”样式中做到这一点,而不覆盖整个行呢
<Setter Property="Template">
?能否将DataGridCell样式添加到内置样式的资源中
<Style x:Key="bold row" TargetType="{x:Type cust:SomeCustomControl}" BasedOn="{StaticResource base style}">
<Style.Resources>
<Style TargetType="{x:Type DataGridCell}">
<Style.Triggers>
<DataTrigger Binding="{Binding RowIndex}" Value="0">
<Setter Property="FontWeight" Value="Bold"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Style.Resources>
</Style>
它应该使用相同的模板,但继承的模板会将触发器应用于所有
DataGridCell
对象难道不能将DataGridCell样式添加到固有样式的资源中吗
<Style x:Key="bold row" TargetType="{x:Type cust:SomeCustomControl}" BasedOn="{StaticResource base style}">
<Style.Resources>
<Style TargetType="{x:Type DataGridCell}">
<Style.Triggers>
<DataTrigger Binding="{Binding RowIndex}" Value="0">
<Setter Property="FontWeight" Value="Bold"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Style.Resources>
</Style>
它应该使用相同的模板,但继承的模板会将触发器应用于所有
DataGridCell
对象这是我尝试的第一件事,但不幸的是它不起作用。我不是经验丰富的WPF程序员,所以我认为样式继承可以用其他方式工作。这个触发器被完全忽略了。这是我尝试的第一件事,但不幸的是它不起作用。我不是经验丰富的WPF程序员,所以我认为样式继承可以用其他方式工作。此触发器被完全忽略。