设置文本选择行时WPF DataGrid行的颜色 [英] Setting the text Colour of a WPF DataGrid Row when row is selected

查看:610
本文介绍了设置文本选择行时WPF DataGrid行的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试更改WPF数据网格中所选行中的Text的颜色。
默认情况下,更改文本颜色白色有没有办法使用样式/触发器等更改?

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}" .../>

如果要将其应用于所有列,您可以将Style的x: / p>

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆