gpt4 book ai didi

C# Silverlight Datagrid - 行颜色更改

转载 作者:太空狗 更新时间:2023-10-29 20:02:16 25 4
gpt4 key购买 nike

如何更改 silverlight 数据网格行的颜色?!

我已经试过了,但它似乎并没有按照我想要的方式工作......随机行的颜色不正确:

 void dataGrid1_LoadingRow(object sender, DataGridRowEventArgs e)
{
var c = e.Row.DataContext as Job;
if (c != null && c.Status.Contains("complete"))
e.Row.Background = new SolidColorBrush(Colors.Green);
else
e.Row.Background = new SolidColorBrush(Colors.Red);
}

最佳答案

微软文档:

To improve performance, the EnableRowVirtualization property is set to true by default. When the EnableRowVirtualization property is set to true, the DataGrid does not instantiate a DataGridRow object for each data item in the bound data source. Instead, the DataGrid creates DataGridRow objects only when they are needed, and reuses them as much as it can. For example, the DataGrid creates a DataGridRow object for each data item that is currently in view and recycles the row when it scrolls out of view.

来源:http://msdn.microsoft.com/en-gb/library/system.windows.controls.datagrid.unloadingrow.aspx

这解释了你一直在经历的行为

因此,正确的(虽然我承认并不容易)解决方案是使用 UnloadingRow 事件来取消设置您设置的样式。

关于C# Silverlight Datagrid - 行颜色更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1509714/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com