如何动态设置Silverlight DataGrid的行后退颜色? [英] how to set Silverlight datagrid row back color dynamically?

查看:112
本文介绍了如何动态设置Silverlight DataGrid的行后退颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我试图根据绑定到数据网格的ItemsSource中的值在Silverlight数据网格中设置行后颜色.我尝试使用转换器,但对我而言不起作用.谁能帮我吗.提前谢谢.

我尝试将silverlight datagrid的RowBackground属性与相应的属性以及转换器绑定.但是要知道,这不是正确的方法.请让我知道是否还有其他方法可以实现.

Hi all,

I am trying to set row back color in a silverlight datagrid based on the values in ItemsSource binded to the datagrid. I tried with converter, but it did not work for me. Can any one help me out. Thanks in advance.

I tried binding RowBackground property of silverlight datagrid with the corresponding property, and converter. But got to know that this is not the right way to do. Please let me know if there is any other way to do this.

推荐答案


//在datagrid LoadingRow事件中
//执行以下操作

var empDetails = e.Row.DataContext作为EmployeeDetails;//EmployeeDetails是您的数据源

如果(empDetails!= null)
{

//您的if条件
如果(empDetails.EmpId == 1)
{
SolidColorBrush scb =新的SolidColorBrush(Colors.Red);//您要保留的颜色
e.Row.Background = scb;
}
}

//由Subash发布
Hi
//In the datagrid LoadingRow event
//do this as below

var empDetails = e.Row.DataContext as EmployeeDetails;//EmployeeDetails is your datasource

if (empDetails != null)
{

//your if condition
if (empDetails.EmpId == 1)
{
SolidColorBrush scb = new SolidColorBrush(Colors.Red);//color you want to keep
e.Row.Background = scb;
}
}

//Posted By Subash


这篇关于如何动态设置Silverlight DataGrid的行后退颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆