2011-08-05 29 views
4

我將datagrid分組到一個子級別。Silverlight:在DataGridRowGroupHeader事件中獲取RowGroupHeader值

像這樣:

 CollectionViewSource pageView = new CollectionViewSource(); 
     pageView.GroupDescriptions.Add(new PropertyGroupDescription("Category")); 
     pageView.GroupDescriptions.Add(new PropertyGroupDescription("SubCategory")); 
     tasksDataGrid.ItemsSource = pageView.View; 

在我的情況有些紀錄沒有子目錄value.Those記錄將顯示在數據網格子類別的空行組標題下。

我想直接顯示在類別行組標題,而不是空頭。

private void TaskDataGrid_LoadingRowGroup(object sender, DataGridRowGroupHeaderEventArgs e) 
    { 
     string RowGroupHeader = // how to get currently loading header value 
     if(RowGroupHeader == string.Empty) 
     { 
      e.RowGroupHeader.Height = 0; 
     } 
    } 

我不能讓當前正在加載RowGroupHeader value.How我才能LoadingRowGroup事件RowGroupHeader值。

幫我解決這個問題。

回答

1

這解決了這個問題。

private void TaskDataGrid_LoadingRowGroup(object sender, DataGridRowGroupHeaderEventArgs e) 
{ 

    var RowGroupHeader = (e.RowGroupHeader.DataContext as CollectionViewGroup); 

       if (RowGroupHeader != null && RowGroupHeader.Items.Count != 0) 
       { 

         MasterTask task = RowGroupHeader.Items[0] as MasterTask; 
         if (task != null && task.SubCategoryName == null) 
          e.RowGroupHeader.Height = 0; 


       } 
} 

感謝djohnsonm的幫助。

+0

沒問題,我的榮幸 –

0

嘗試此操作,但插入對應於Header值的虛擬機和屬性的名稱。

private void TaskDataGrid_LoadingRowGroup(object sender, DataGridRowGroupHeaderEventArgs e) 
{ 
    string RowGroupHeader = (e.RowGroupHeader.DataContext as ParentVM).VMProperty 
    if(RowGroupHeader == string.Empty) 
    { 
     e.RowGroupHeader.Height = 0; 
    } 
} 
+0

e.RowGroupHeader.DataContext是MS.Internal.CollectionViewGroupInternal的類型。如果我投影到ParentVM,將獲得空值。 – Hukam