我有一个DataGrid,它使用AlternatingRowBackground使自己更容易阅读。在相同的网格中,我还根据我的"IsMouseOver" Setter Property文件中的App.xaml文件对行进行背景色更改。我遇到的问题是,具有交替颜色的行(它们不是白色的),当鼠标悬停在它上面时,不会更改为"IsMouseOver"颜色。基本上,AlternatingRowBackground的颜色优先于我的RowStyle。当鼠标悬停在它们上面时,如何使颜色行也发生变化?
App.xaml:
<!-- DataGrid Row Style -->
<Style x:Key="RowStyleWithAlternation" TargetType="DataGridRow">
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="Background" Value="GhostWhite"/>
<Setter Property="FontWeight" Value="Normal"/>
<Setter Property="ContextMenu" Value="{x:Null}"/>
<Style.Triggers>
<Trigger Property="AlternationIndex" Value="1">
<Setter Property="Background" Value="#FFD0D0E0"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="Purple"/>
</Trigger>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="#F9F99F" />
</Trigger>
</Style.Triggers>
</Style>用户控制xaml:
<DataGrid ... AlternatingRowBackground="Gray" RowStyle="{StaticResource RowStyleWithAlternation}" ... />发布于 2014-12-17 19:34:22
如果您按以下方式更改您的UserControl.xaml,它就会工作:
<DataGrid RowStyle="{StaticResource RowStyleWithAlternation}" AlternationCount="2" />背景是通过行上的AlternationIndex触发器设置的,该触发器没有优先于IsMouseOver。
我在这篇文章上找到了答案:
WPF Style Trigger for DataGridRow Background Color Trumped by AlternatingRowBackground Brush
https://stackoverflow.com/questions/27533022
复制相似问题