【问题标题】:Styling DataGrid SelectedRow in App.Config在 App.Config 中设置 DataGrid SelectedRow 的样式
【发布时间】:2016-04-01 17:54:31
【问题描述】:

我的App.Config 中有一个样式,我用它来为程序中的每个Rectangle 着色;

<Style TargetType="Rectangle">
    <Setter Property="Fill" Value="LightBlue"></Setter>
</Style>

基本上我也想做同样的事情,但更改我的DataGrid 中突出显示的行的颜色。这是我迄今为止所尝试的;

<Style TargetType="DataGridRow">
    <Style.Triggers>
        <Trigger Property="DataGridRow.IsSelected" Value="True">
            <Setter Property="Background" Value="Red" />
        </Trigger>
    </Style.Triggers>
</Style>

但这不会改变突出显示行的颜色,它仍然是WPF 中的默认颜色。如何将其编程到我的 App.Config 中以使行颜色发生变化?

【问题讨论】:

    标签: c# wpf datagrid app-config


    【解决方案1】:

    为此,您必须覆盖 SystemColors.HighlightBrushKey。这就是你可以做到的方式

    <DataGrid.Resources>
      <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" 
                       Color="Red"/>
    </DataGrid.Resources>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-12-02
      • 1970-01-01
      • 2017-01-25
      • 2014-06-13
      • 2012-02-02
      • 2014-09-28
      • 2011-06-18
      相关资源
      最近更新 更多