【问题标题】:Datagrid ActualHeight without column header height不带列标题高度的 Datagrid ActualHeight
【发布时间】:2018-09-07 09:45:10
【问题描述】:

我试图在不考虑列标题高度的情况下获取 WPF Datagrid 的 ActualHeight。

如何获得?非常感谢

【问题讨论】:

    标签: .net wpf datagrid


    【解决方案1】:

    您可以通过访问DataGrid 的DataGridRowsPresenter 来获取它。喜欢,

    var dataGridRowsPresenter = FindVisualChild<DataGridRowsPresenter>(grid);
    double actualHeight = dataGridRowsPresenter.ActualHeight;
    

    查找control的Visual Child的方法:

    public static T FindVisualChild<T>(DependencyObject current) where T : DependencyObject
    {
        if (current == null) return null;
        int childrenCount = VisualTreeHelper.GetChildrenCount(current);
        for (int i = 0; i < childrenCount; i++)
        {
            DependencyObject child = VisualTreeHelper.GetChild(current, i);
            if (child is T) return (T)child;
            T result = FindVisualChild<T>(child);
            if (result != null) return result;
        }
        return null;
    }
    

    【讨论】:

    • DataGridRowsPresenter,就是这样!非常感谢
    猜你喜欢
    • 1970-01-01
    • 2016-11-10
    • 1970-01-01
    • 2013-10-01
    • 2010-10-22
    • 2020-01-06
    • 1970-01-01
    • 1970-01-01
    • 2016-06-12
    相关资源
    最近更新 更多