2017-07-01 129 views
0

我使用DataGrid並需要更改一行的背景顏色。 DataGrid使用滾動,當我嘗試此代碼時,背景也滾動。在運行時更改Datagrid wpf中的行的背景顏色

DataGridRow row = (DataGridRow)gg.ItemContainerGenerator.ContainerFromIndex(i);     
row.Background = Brushes.Red; 
+2

有關GUI方面改變的東西,我建議你使用WPF數據綁定 – Tony

回答

0

有事件被稱爲「LoadingRow通知」,要求當行加載到GridView你可以在那裏把你的條件,如:

private void table_LoadingRow(object sender, DataGridRowEventArgs e) 
    { 
     if (((MyData)e.Row.DataContext).Module.Trim().Equals("SomeText")) 
     { 
      e.Row.Foreground = new SolidColorBrush(Colors.Red); 
     } 
    } 
相關問題