WPF使用中知识点总结二

DataGrid的行,单元格根据绑定数据的变化,改变样式:

一 : 对行的样式添加DataTrigger,当Binding的State值为0时,行的Background,IsEnabled两个属性改变

 1   <DataGrid.RowStyle>
2 <Style TargetType="DataGridRow">
3 <Style.Triggers>
4 <DataTrigger Binding="{Binding Path=State,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Value="0">
5 <Setter Property="Background" Value="Red"></Setter>
6 <Setter Property="IsEnabled" Value="False"></Setter>
7 </DataTrigger>
8 </Style.Triggers>
9 </Style>
10 </DataGrid.RowStyle>

二: 对单元格的样式添加DataTrigger,当Binding的State值为0时,行的Background,IsEnabled两个属性改变

 1   <DataGridTextColumn.CellStyle>
2 <Style TargetType="DataGridCell" >
3 <Style.Triggers>
4 <DataTrigger Binding="{Binding Path=State,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" Value="0">
5 <Setter Property="Background" Value="Red"></Setter>
6 <Setter Property="IsEnabled" Value="False"></Setter>
7 </DataTrigger>
8 </Style.Triggers>
9 </Style>
10 </DataGridTextColumn.CellStyle>

  

  

posted @ 2011-07-18 16:29  风枫峰  阅读(817)  评论(0编辑  收藏  举报