DataGrid数据绑定后,行设置颜色

Silverlight DataGrid数据行背景颜色控制

sdk:DataGrid数据绑定后,部分特殊的行需要用不同的背景颜色来显示。(注册DataGrid的LoadingRow事件)
private void radGridView_LoadingRow(object sender, DataGridRowEventArgs e)
{

//获取当前加载的行标(从0开始)
int i = e.Row.GetIndex();

//获取DataGrid绑定的数据集合
ObservableCollection list = radGridView.ItemsSource as ObservableCollection;

//遍历集合

foreach (CntrMstModel model in list)
{
if (i.ToString() == model.SID)
{

//改变颜色的行条件
if (model.ID == "1")
e.Row.Background = new SolidColorBrush(Colors.Gray);
else
e.Row.Background = new SolidColorBrush(Colors.White);
}
}
}



说明:CntrMstModel 这是我的model实例。

相关文档
最新文档