找回密码
 立即注册

QQ登录

只需一步,快速开始

suntongowen
初级会员   /  发表于:2015-3-24 11:56:00
6#
回复 5楼Alice的帖子

做了一个小DEMO,想让C2列是“NO”的行变颜色,请指点一下,实现不了

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复 使用道具 举报
Alice
社区贡献组   /  发表于:2015-3-24 09:48:00
5#
回复 4楼suntongowen的帖子

我们这里没有现成的例子。
不过我可以给你提供基本的思路,供你参考。
需要重新定义'DataGridRowPresenter’ ,然后绑定必要元素(BackgroundElement)
基本步骤:
1.C1DataGrid设置RowStyle:
  1. <c1:C1DataGrid   x:Name="grid"   RowStyle="{StaticResource rowstyle}"/>
复制代码

2.继承IValueConverter接口,在Convert方法里判断某种条件下设置背景色。
比如:
  1. public class MyConverter : IValueConverter
  2.     {
  3.         public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  4.         {
  5.             var p = value as Product;  // typecast the data item here
  6.            if (p != null)
  7.            {
  8.                if (p.Available == true)
  9.                {
  10.                    return new SolidColorBrush(Colors.Yellow);
  11.                }
  12.                else return new SolidColorBrush(Colors.White);
  13.            }
  14.            return new SolidColorBrush(Colors.White);
  15.         }

  16.         public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  17.         {
  18.             return null;
  19.         }
  20.     }
复制代码


3.在XAML里,重写Style,类型为DataGridRowPresenter。
  1. <local:MyConverter x:Key="converter"/>
  2.        <Style x:Key="rowstyle" TargetType="c1:DataGridRowPresenter">
  3.            <Setter Property="BorderThickness" Value="0"/>
  4.            <Setter Property="Template">
  5.                <Setter.Value>
  6.                    <ControlTemplate TargetType="c1:DataGridRowPresenter" >
  7. //在这里重写Template,下面这句代码是参考的。
  8. <Border x:Name="BackgroundElement" Background="{Binding Path=Row.DataItem,RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource converter}}" />
  9.                                             </ControlTemplate>
  10.                </Setter.Value>
  11.            </Setter>
  12.        </Style>
复制代码
请点击评分,对我的服务做出评价!  5分为非常满意!

葡萄城控件服务团队

官方网站: http://www.gcpowertools.com.cn
回复 使用道具 举报
suntongowen
初级会员   /  发表于:2015-3-23 18:15:00
地板
回复 2楼Alice的帖子

Convert的实现方法能给发例子代码吗?多谢
回复 使用道具 举报
suntongowen
初级会员   /  发表于:2015-3-23 17:47:00
板凳
回复 2楼Alice的帖子

实际项目,不方便发demo
回复 使用道具 举报
Alice
社区贡献组   /  发表于:2015-3-23 17:12:00
沙发
回复 1楼suntongowen的帖子

还有一种Converter的方法。
对Row.Backgroud,自己通过Conveter来设置背景色,在Converter里根据需求条件更改颜色。
但不确定你所提到的使用场景,会不会出问题。

另外,你上面提到的使用场景出现了问题,你可以将出现该问题的Demo和必然步骤发给我们,我们可以帮你看看是什么问题。
请点击评分,对我的服务做出评价!  5分为非常满意!

葡萄城控件服务团队

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