答案 0 :(得分:1)
您可以通过访问DataGridRowsPresenter
中的DataGrid
来获得它。喜欢,
var dataGridRowsPresenter = FindVisualChild<DataGridRowsPresenter>(grid);
double actualHeight = dataGridRowsPresenter.ActualHeight;
找到control
的可视子级的方法:
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;
}