找回密码
 立即注册

QQ登录

只需一步,快速开始

CanYou8

银牌会员

67

主题

191

帖子

2047

积分

银牌会员

积分
2047

活字格认证微信认证勋章元老葡萄

CanYou8
银牌会员   /  发表于:2015-5-29 11:12  /   查看:5315  /  回复:1
  1.                 <c1:C1DataGrid Name="C1Datagrid1"  ItemsSource="{Binding CustomerList}" Style="{StaticResource DarkGray}"  IsReadOnly="True">
  2.                     <c1:C1RowIndexHeaderBehavior.RowIndexHeaderBehavior>
  3.                         <c1:C1RowIndexHeaderBehavior InitialIndex="1"/>
  4.                     </c1:C1RowIndexHeaderBehavior.RowIndexHeaderBehavior>
  5.                     <c1:C1DataGrid.Columns>
  6.                         <c1:DataGridTextColumn Width="80" Header="客户类型" Binding="{Binding CustomerType}"/>
  7.                         <c1:DataGridTextColumn Width="80" Header="姓名" Binding="{Binding Name}"/>
  8.                         <c1:DataGridTextColumn Width="70" Header="年龄" Binding="{Binding Age}"/>
  9.                     </c1:C1DataGrid.Columns>
  10.                 </c1:C1DataGrid>
复制代码


上述代码实现的列表,使用的是WPF中C1DataGrid控件。如果列表中客户类型值为1或2。请问能不能根据客户类型的值,对这一行的数据进行背景色或者字体颜色的动态控制?需要如何做呢?

1 个回复

倒序浏览
Alice
社区贡献组   /  发表于:2015-5-29 14:29:00
沙发
回复 1楼CanYou8的帖子

感谢对该问题的反馈。
根据我的理解,你需要条件设置值。
C1DataGrid有提供LoadedCellPresenter/UnloadedCellPresenter事件来实现。在事件中设置你所需要的values/styles。

结合到你的需求,应该是在该事件中获取到类型的值,然后根据值判断颜色,e.Cell.Presenter.Background就可以给满足条件的单元格设置背景色,e.Cell.Presenter.Foreground可以设置字体颜色。

该事件的使用方法可以参考随机安装实例:
\Documents\ComponentOne Samples\Studio for WPF\C1.WPF.DataGrid\CS\DataGridSamples\Advanced\ConditionalFormat
请点击评分,对我的服务做出评价!  5分为非常满意!

葡萄城控件服务团队

官方网站: http://www.gcpowertools.com.cn
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部