2014-10-09 30 views
0

如何以編程方式應用radgridview單元格的背景顏色?我發現當我向上或向下滾動時背景顏色不再存在。如何從代碼背後維護radgridview單元格的背景顏色?

xaml.cs

private void dgQueue_RowLoaded(object sender, RowLoadedEventArgs e) 
{ 
    GridViewRow GrdRow = e.Row as GridViewRow; 
    EVQueue objEV = e.Row.DataContext as EVQueue; 
    TextBlock txtActivityDate = null; 
    TextBlock txtSendDate = null; 
    int activityDateIndex = 0; 
    if (GrdRow != null) 
    { 
     for (int index = 0; index < GrdRow.Cells.Count; index++) 
     { 
      if (GrdRow.Cells[index].Column.UniqueName.Equals("ActivityDate", StringComparison.OrdinalIgnoreCase)) 
      { 
       if (objEV.ActivityDate != null) 
       {       
        txtActivityDate = (TextBlock)e.Row.Cells[index].Content; 
        activityDateIndex = index; 
       } 
      } 

      if (GrdRow.Cells[index].Column.UniqueName.Equals("SendDate", StringComparison.OrdinalIgnoreCase)) 
      { 
       if (objEV.SendDate != null) 
       { 
        txtSendDate = (TextBlock)e.Row.Cells[index].Content; 
       } 
      } 
     }     
     if (!string.IsNullOrEmpty(txtActivityDate.Text) && !string.IsNullOrEmpty(txtSendDate.Text)) 
     {     
      if (Convert.ToDateTime(txtActivityDate.Text, CultureInfo.InvariantCulture) > Convert.ToDateTime(txtSendDate.Text, CultureInfo.InvariantCulture)) 
      { 
       e.Row.Cells[activityDateIndex].Background = Brushes.Yellow; 
      } 
     } 
    } 
} 

XAML:

<telerik:RadGridView Name="dgQueue" 
         Grid.Row="2" 
         Grid.Column="0" 
         Height="580" 
         HorizontalAlignment="Stretch" 
         VerticalAlignment="Top" 
         AutoGenerateColumns="False" 
         FontSize="12" 
         IsReadOnly="True" 
         ItemsSource="{Binding}" 
         ShowColumnFooters="true" 
         ShowGroupPanel="False" 
         telerikControls:StyleManager.Theme="Summer" 
         UseLayoutRounding="True" 
         RowLoaded="dgQueue_RowLoaded" 
         AllowDrop="False" TabIndex="14" > 
    <telerik:RadGridView.Columns> 
     <telerik:GridViewDataColumn Width="*" UniqueName="ActivityDate" Name="datacolActivityDate" 
            DataMemberBinding="{Binding ActivityDate}"           
            Header="Activity Date" /> 

     <telerik:GridViewDataColumn Width="*" UniqueName="SendDate" 
            DataMemberBinding="{Binding SendDate}" 
            Header="Send Date" /> 
    </telerik:RadGridView.Columns> 
</telerik:RadGridView> 
+0

請將您的代碼顯示在您應用背景顏色的位置。 – FeliceM 2014-10-09 18:43:38

回答

0

我曾經對此問題看到的,我有一輪是我發現那裏的風格,我想在使用方式SDK並將樣式放入我的應用程序中。

然後,我去了Template屬性,找到根網格並將TemplateBinding設置爲根網格。

儘管您可能面臨的問題有所不同。它可能是一個虛擬化。您可能需要在每次出現時真正設置背景,但不確定這是不錯的做法。

相關問題