2011-02-22 17 views

回答

1

我不確定您的意思是什麼,但您可以通過在Visual Tree中找到它們來獲取當前生成的所有DataGridRow。這將基本上給你,因爲在DataGrid

private List<DataGridRow> GetDataGridRows(DataGrid dataGrid) 
{ 
    return GetVisualChildCollection<DataGridRow>(c_dataGrid);    
} 

GetVisualChildCollection

public static List<T> GetVisualChildCollection<T>(object parent) where T : FrameworkElement 
{ 
    List<T> visualCollection = new List<T>(); 
    GetVisualChildCollection(parent as DependencyObject, visualCollection); 
    return visualCollection; 
} 
private static void GetVisualChildCollection<T>(DependencyObject parent, List<T> visualCollection) where T : FrameworkElement 
{ 
    int count = VisualTreeHelper.GetChildrenCount(parent); 
    for (int i = 0; i < count; i++) 
    { 
     DependencyObject child = VisualTreeHelper.GetChild(parent, i); 
     if (child is T) 
     { 
      visualCollection.Add(child as T); 
     } 
     else if (child != null) 
     { 
      GetVisualChildCollection(child, visualCollection); 
     } 
    } 
} 
+0

visible =」在當前屏幕上顯示「 – user626528

0

我的方式使用了虛擬化的所有可見DataGridRow S和可能多了一些我們已經完成了它,通過連接到DataGrid的LoadingRowUnloadingRow事件。

下面是一個例子

HashSet<DataGridRow> loadedRows 

    private void HandleUnloadingRow(object sender, DataGridRowEventArgs e) 
    { 
     _loadedRows.Remove(e.Row); 
    } 

    private void HandleLoadingRow(object sender, DataGridRowEventArgs e) 
    { 
     _loadedRows.Add(e.Row); 
    } 
相關問題