码迷,mamicode.com
首页 > Windows程序 > 详细

DevExpress WPF GridControl 绑定行的前景色和背景色

时间:2014-12-05 12:22:15      阅读:491      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   ar   color   使用   sp   on   div   

 

怎样通过判断一个行内的字段的值来改变该行的颜色呢?

我们使用绑定来做:

GridControl控件的行的概念很模糊,我们要想动态改变行的颜色不是设置一下Background就能做到的,我们需要改变它的RowStyle,下面是代码:

1 <Style x:Key = "RowStyle" BasedOn = "{StaticResource {dxgt:GridRowThemeKey ResourceKey=RowStyle}}" TargetType = "{x:Type dxg:GridRowContent}">
2             <Setter Property = "Background" Value="{Binding Row, Converter={StaticResource alarmLevelConverter}}"/>
3         </Style>

把它赋给

1     <dxg:GridControl.View>
2                 <dxg:TableView RowStyle="{DynamicResource RowStyle}" />
3             </dxg:GridControl.View>        

然后转换器怎么写呢?

 1     [ValueConversion(typeof(AlarmHappeningClass), typeof(Brush))]
 2 
 3     public class AlarmLevelConverter : IValueConverter
 4     {
 5 
 6         public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
 7         {
 8             AlarmHappeningClass alarmrow = value as AlarmHappeningClass;
 9             if (alarmrow == null)
10                 return Brushes.Transparent; ;
11             if (alarmrow.AlarmLevel=="紧急")
12                 return Brushes.Red;
13             else if (alarmrow.AlarmLevel == "重要")
14                 return Brushes.Orange;
15             return Brushes.Transparent;
16         }
17 
18         public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
19         {
20             throw new NotSupportedException();
21         }
22 
23     }

上面的转换器,根据自己的需要改代码就行了,如果在加trigger,自己在代码里面加就可以了。

 

DevExpress WPF GridControl 绑定行的前景色和背景色

标签:style   blog   io   ar   color   使用   sp   on   div   

原文地址:http://www.cnblogs.com/xiujian/p/4146151.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!