选择行时设置 WPF DataGrid 行的文本颜色 [英] Setting the text Colour of a WPF DataGrid Row when row is selected
本文介绍了选择行时设置 WPF DataGrid 行的文本颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试更改 WPF 数据网格中选定行中文本的颜色.默认情况下,它会将文本颜色更改为白色,是否可以使用样式/触发器等进行更改?
I'm trying to change the colour of Text in the selected row in a WPF datagrid. By default it changes the text colour white is there a way to change this using styles / triggers etc?
提前致谢!
推荐答案
试试这个
<Style x:Key="DataGridCellStyle" TargetType="{x:Type DataGridCell}" >
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Foreground" Value="Green"/>
</Trigger>
</Style.Triggers>
</Style>
然后你可以在你认为合适的列中使用它
Then you can use it in the columns that you see fit like
<DataGrid ...>
<DataGrid.Columns>
<DataGridTextColumn CellStyle="{StaticResource DataGridCellStyle}" .../>
如果您希望它应用于所有列,您可以将样式的 x:key 更改为
If you want it to apply to all columns you can change the x:key of the Style to
<Style x:Key="{x:Type DataGridCell}" TargetType="{x:Type DataGridCell}" >
这篇关于选择行时设置 WPF DataGrid 行的文本颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文