WPF DataGrid 触发器

<DataGrid.RowHeaderStyle>
    <Style TargetType="DataGridRowHeader"> <Style.Triggers> <DataTrigger Binding="{Binding Type}" Value="1"> <Setter Property="Background" Value="DeepSkyBlue">Setter> DataTrigger> <DataTrigger Binding="{Binding Type}" Value="0"> <Setter Property="Background" Value="White">Setter> DataTrigger> Style.Triggers> Style> DataGrid.RowHeaderStyle> 

Type为数据表中某一列
注意:TargetType="DataGridRowHeader"
修改的属性是行头的背景颜色,效果如下:

 
WPF DataGrid 触发器_第1张图片


或者:

<DataGrid.ColumnHeaderStyle>
    <Style> <Setter Property="DataGridColumnHeader.Background" Value="DeepSkyBlue">Setter> Style> DataGrid.ColumnHeaderStyle> 

Property="DataGridColumnHeader.Background" 不指名DataGridColumnHeader会报错

转载于:https://www.cnblogs.com/Lulus/p/8158354.html

你可能感兴趣的:(WPF DataGrid 触发器)