如何:更改DataGrid IsSelected后台(C#,WPF)
如何:更改DataGrid IsSelected后台(C#,WPF) 我的如何:更改DataGrid IsSelected后台(C#,WPF),c#,wpf,xaml,datagrid,background,C#,Wpf,Xaml,Datagrid,Background,如何:更改DataGrid IsSelected后台(C#,WPF) 我的App.xaml中确实有以下代码: <Application.Resources> <Style TargetType="{x:Type DataGridRow}"> <Style.Triggers> <Trigger Property="IsMouseOver" Value="True"> &l
App.xaml中确实有以下代码:
<Application.Resources>
<Style TargetType="{x:Type DataGridRow}">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="Orange" />
</Trigger>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="WhiteSmoke" />
</Trigger>
</Style.Triggers>
</Style>
</Application.Resources>
不幸的是,我得到的结果如下:
我需要做什么来解决我的问题?您必须设置DataGridCell
上的IsSelected
属性的样式,因为它(显然)是在DataGridRow
之后呈现的。您可以将这一位Xaml添加到数据网格资源中
<DataGrid.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Yellow"/>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Red"/>
</DataGrid.Resources>
当选择一行时,两个笔刷一起工作以设置背景/前景
要设置DataGrid行的默认颜色,可以添加以下代码段
<DataGrid.RowStyle>
<Style TargetType="DataGridRow">
<Setter Property="Background" Value="Pink" />
<Setter Property="Foreground" Value="DodgerBlue"/>
</Style>
</DataGrid.RowStyle>
这将背景设置为粉红色,前景设置为淡蓝色
有关SystemColor静态资源的更多信息位于可以,但现在我无法再看到我的文本。它被白烟
背景覆盖。@异常然后在IsSelected
触发器中添加新的setter,以更改您选择的单元格前景
颜色。好的,谢谢。第一个有效,第二个无效。然而,我决定使用方法一。不幸的是,我现在需要改变前景。我该怎么做?@Exception为SystemColor.ControlTextBrush添加一个条目并检查您的result@Exception,在样式中添加了默认属性,可以修复第二个不起作用的原因…好吧,我试图修复我的问题,但您发送了鼠标悬停效果和一般背景的代码。我只需要IsSelected
属性…@异常,只是检查一下,你看到关于SystemColor.ControlTextBrush的评论了吗?