gpt4 book ai didi

c# - DataGrid -- AlternatingRowBackground 颜色干扰 "IsMouseOver"颜色

转载 作者:太空狗 更新时间:2023-10-29 23:38:31 27 4
gpt4 key购买 nike

我有一个 DataGrid,它使用 AlternatingRowBackground 使其更易于阅读。在同一个网格中,我还根据 App.xaml 文件中的 "IsMouseOver" Setter Property 更改了行的背景颜色。我遇到的问题是,当鼠标悬停在具有交替颜色(它们不是白色)的行上时,它们不会更改为 "IsMouseOver" 颜色。基本上 AlternatingRowBackground 颜色优先于我的 RowStyle。如何使彩色行在鼠标悬停在它们上方时也发生变化?

应用程序.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}" ... />

最佳答案

如果您按如下方式更改 UserControl.xaml,它会起作用:

<DataGrid RowStyle="{StaticResource RowStyleWithAlternation}" AlternationCount="2" />

背景是通过行上的 AlternationIndex 触发器设置的,它的优先级不高于 IsMouseOver。

我在这篇文章中找到了答案:

WPF Style Trigger for DataGridRow Background Color Trumped by AlternatingRowBackground Brush

关于c# - DataGrid -- AlternatingRowBackground 颜色干扰 "IsMouseOver"颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27533022/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com