c# - 如何在 Silverlight 中查找可见的 DataGrid 行?

标签 c# silverlight

如何在 Silverlight 中查找可见的 DataGrid 行?

最佳答案

我不确定您所说的可见 DataGridRow 是什么意思,但是您可以通过在可视化树中找到它们来获取当前生成的所有 DataGridRow。这基本上会为您提供所有可见的 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);
        }
    }
}

关于c# - 如何在 Silverlight 中查找可见的 DataGrid 行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5079130/

相关文章:

silverlight - 如何调整 Silverlight 3 应用程序和所有子控件的大小并保持纵横比

c# - 如何从数组中删除特定元素?

c# - 使用结构图获取和/或弹出通用接口(interface)的所有实现

c# - 如何最小化Windows中的内存使用

c# - wordpress 最好的 C# 代码高亮插件是什么?

c# - 使用 EWS 阅读电子邮件时处理非法 XML 值

c# - ()=> 在 silverllight 中有什么用

Silverlight 图像按钮用户控件

Silverlight UI 文化

c# - 链接的 .CS 文件和 WCF 服务的引用不明确