我在windows 7上使用Visual Studio 2012。我需要知道以下Grid选中行的样式为什么在背景和前景色方面无法正常工作,但对于其他属性(如BorderBrush和BorderThickness等)却能完美工作?虽然我可以在鼠标悬停在Grid行上时看到它们正在改变。
<Style x:Key="gridRowStyle" TargetType="{x:Type DataGridRow}">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="PeachPuff"/>
<Setter Property="Foreground" Value="BlueViolet"/>
</Trigger>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="PeachPuff"/>
<Setter Property="Foreground" Value="BlueViolet"/>
<Setter Property="BorderBrush" Value="BlueViolet" />
<Setter Property="BorderThickness" Value="2" />
</Trigger>
</Style.Triggers>
</Style>
这是我在网格上使用的方法。
<DataGrid RowStyle="{StaticResource gridRowStyle}">
我更注重了解“为什么”,而不是问题的解决方案,因为如果我使用单元格样式而不是行样式,则已经有了解决方案,如下所示:
<Style x:Key="gridCellStyle" TargetType="{x:Type DataGridCell}">
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="PeachPuff"/>
<Setter Property="Foreground" Value="BlueViolet"/>
</Trigger>
</Style.Triggers>
</Style>