的背景下,我能够通过下面的C#代码改变DATACELL的背景 -改变DataGrid单元格
private void Retrieve_rows(object item)
{
DataRow row = mygrid.GetContainerFromItem(item) as DataGrid.DataRow;
if (row != null)
{
SolidColorBrush redColor = new SolidColorBrush (Colors.Red);
foreach (DataGrid.DataCell cell in row.Cells)
{
var dc = ((System.Windows.FrameworkElement)(((DataGrid.Cell)(cell)).ParentRow)).DataContext;
// get my custom object and change color if IsBlank value is set to true
MyRowObject rowObject = dc as MyRowObject;
for (int counter = 0; counter < rowObject.values.Count; counter++)
{
if (rowObject.values[counter].IsBlank == true)
row.Cells[counter].Background = redColor;
}
}
return;
}
}
}
但有了这个代码,应用程序性能下降在很大程度上。有没有办法将上面的代码转换为XAML触发器/或其他方式来提高网格的性能。
嗨,谢谢,谢谢你的回复。但我已经尝试过下面的xaml代码,这是行不通的。 MultiDataTrigger> –
user1134489
2012-01-06 15:09:11
请更具体一点 - 您打算如何处理这个多数据触发器?这似乎有点偏题... – 2012-01-06 15:14:18