【发布时间】:2012-08-23 13:28:32
【问题描述】:
我正在使用 WPF DataGrid 并通过使用类 RowItem 在运行时添加行
public class RowItem //Class
{
public int Rule_ID { get; set; }
public string Rule_Desc { get; set; }
public Int64 Count_Of_Failure { get; set; }
}
adding row at run time like :
dgValidateRules.Items.Add(new RowItem() { Rule_ID = ruleID, Rule_Desc = ruleDesc, Count_Of_Failure = ttlHodlings });
使用下面的 Loading Row 事件代码来更改数据网格行的颜色。但它不起作用。
private void dgValidateRules_LoadingRow(object sender, DataGridRowEventArgs e)
{
for (int i = 1; i < dgValidateRules.Items.Count; i++)
{
if (((RowItem)dgValidateRules.Items[i]).Count_Of_Failure == 0)
e.Row.Foreground = new SolidColorBrush(Colors.Black);
else
e.Row.Foreground = new SolidColorBrush(Colors.Red);
}
}
谁能告诉我解决方案?
【问题讨论】:
-
Wooow 看看你的问题....你希望有人会费心去读那些烂摊子吗?请在发布之前格式化您的问题。
-
你到底想改变什么。?行的背景颜色或前景色。?请注意,前景色会改变文本颜色。
-
是的,我只需要更改文本颜色。
标签: c# wpf wpfdatagrid