的背景下,我能夠通過下面的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