2009-12-07 67 views
2

我在Silverlight 3中使用PagedCollectionView對數據網格中的項目進行分組。我想檢測何時單擊組標題,但6小時後仍然無法找到任何方法來執行此操作。Silverlight 3 DataGrid分組 - 檢測組標題單擊或標題展開/摺疊

(因此,當一個摺疊頭被點擊我可以動態加載該組的內容)

數據網格被填充像這樣:

PagedCollectionView集合=新PagedCollectionView(orgMembers); collection.GroupDescriptions.Add(new PropertyGroupDescription(「Generation」));

DataGrid1.ItemsSource = collection;

回答

4

編寫擴展方法來找到特定類型的父元素:

public static T FindParentOfType<T>(this FrameworkElement element) 
    { 
     var parent = VisualTreeHelper.GetParent(element) as FrameworkElement; 

     while (parent != null) 
     { 
      if (parent is T) 
       return (T)(object)parent; 

      parent = VisualTreeHelper.GetParent(parent) as FrameworkElement; 
     } 
     return default(T); 
    } 

手柄上DataGrid中的MouseLeftButtonUp事件:

private void PassportGrid_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) 
    { 

     DataGridRowGroupHeader rgh = (e.OriginalSource as FrameworkElement).FindParentOfType<DataGridRowGroupHeader>(); 
     if (rgh != null && rgh.DataContext is CollectionViewGroup) 
     { 
      var stuff = (rgh.DataContext as CollectionViewGroup); 
      var items = stuff.Items; 
     } 
    } 

您可以單擊的羣體獲取信息及其物品收集(如上所示)