RowVirtualization cause incorrect background color for rows

后端 未结 3 866
死守一世寂寞
死守一世寂寞 2020-12-06 22:33

I have a WPF application and there is a Datagrid in some pages. This datagrid needs to load 5000 rows at once (Pagination is not an option for me) and this takes ages. I set

3条回答
  •  不思量自难忘°
    2020-12-06 22:53

    Well as Eirik said it might be too late. but i would be glad if it can help others. You can do this EnableRowVirtualization = "True" (so it won't affect your performance in case of large data). And just code this on dgOrders_LoadingRow event.

    private void dgOrders_LoadingRow(object sender, DataGridRowEventArgs e)
    {
    
            OrderDetail item = e.Row.Item as OrderDetail; //parse data into your bject type which is 
            if (item != null)
            {
                 if (item.Note== "Loss") //your condition
                 {
                     e.Row.Background = Brushes.Red;
                 }
                 else                    //otherwise default color
                 {
                     e.Row.Background = Brushes.White;
                 }
            }
        }
    

提交回复
热议问题