小编use*_*895的帖子

所选行的WPF DataGrid RowStyle不更改背景和前景色

我在Windows 7上使用Visual Studio 2012.我需要知道为什么Grid的选定行的以下样式不适用于背景和前景色,但对于BorderBrush和BorderThickness等其他属性的效果非常好?虽然我可以看到它们在鼠标悬停在网格行上时发生变化

<Style x:Key="gridRowStyle" TargetType="{x:Type DataGridRow}">
    <Style.Triggers>
        <Trigger Property="IsMouseOver" Value="True">
            <Setter Property="Background" Value="PeachPuff"/>
            <Setter Property="Foreground" Value="BlueViolet"/>
        </Trigger>
        <Trigger Property="IsSelected" Value="True">
            <Setter Property="Background" Value="PeachPuff"/>
            <Setter Property="Foreground" Value="BlueViolet"/>
            <Setter Property="BorderBrush" Value="BlueViolet" />
            <Setter Property="BorderThickness" Value="2" />

        </Trigger>
    </Style.Triggers>
</Style>
Run Code Online (Sandbox Code Playgroud)

这是我在网格上使用的方式.

<DataGrid RowStyle="{StaticResource gridRowStyle}">
Run Code Online (Sandbox Code Playgroud)

我强调要知道"为什么"而不是解决问题,因为我已经有问题的解决方案,如果我使用网格单元格样式而不是像下面的rowstyle:

<Style x:Key="gridCellStyle" TargetType="{x:Type DataGridCell}">
    <Style.Triggers>
        <Trigger Property="IsSelected" Value="True">
            <Setter Property="Background" Value="PeachPuff"/>
            <Setter Property="Foreground" Value="BlueViolet"/>
        </Trigger>
    </Style.Triggers>
</Style>
Run Code Online (Sandbox Code Playgroud)

wpf datagrid background-color

6
推荐指数
1
解决办法
6902
查看次数

标签 统计

background-color ×1

datagrid ×1

wpf ×1