2011-06-01 20 views
0

我有一個數據網格,它的行根據某些條件着色..有一個垂直滾動條用於我的數據網格。如果用戶滾動數據網格,彩色行的索引[R得到改變。對於例如:如果2行彩色如果用戶向下滾動,並配備了彩色行的索引是越來越亂了......DataGrid在Silverlight 4.0中滾動時的隨機行爲中的錯誤

這裏是代碼....

dggeneralconfiguration.LoadingRow += new EventHandler<DataGridRowEventArgs>(grid1_LoadingRow); 
       dggeneralconfiguration.UnloadingRow += new EventHandler<DataGridRowEventArgs>(grid1_UnloadingRow); 
void grid1_LoadingRow(object sender, DataGridRowEventArgs e) 
     { 
      ShowGeneralGrid c = e.Row.DataContext as ShowGeneralGrid; 

      if (c.Status == false) 
      { 
       if (e.Row != null) 
       { 
        e.Row.Background = new SolidColorBrush(Colors.Red); 
        //e.Row.Background = new SolidColorBrush(Colors.Transparent); 
       } 
      } 
     } 
     void grid1_UnloadingRow(object sender, DataGridRowEventArgs e) 
     { 
      ShowGeneralGrid c = e.Row.DataContext as ShowGeneralGrid; 

      if (c.Status == false) 
      { 
       if (e.Row != null) 
       { 
        e.Row.Background = new SolidColorBrush(Colors.Red); 
        //e.Row.Background = new SolidColorBrush(Colors.Transparent); 
       } 
      } 
     } 

回答

2

比從未更好的遲到。 ;-)。我也有類似的問題..嘗試在卸載行事件時將行背景分配給null。

private void dg_UnloadingRow(object sender, DataGridRowEventArgs e) 
    { 
     e.Row.Background = null; 
    }