是否可以访问我在数据网格的属性列表中找不到的水平偏移?
感谢
在XAML 中
<DataGrid Name="dataGrid1" ..... />
如果您想访问HorizontalOffset,您需要访问Datagrid 中包含的ScrollViewer
访问ScrollViewer的一种可能方法是
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(dataGrid1); i++)
{
if (VisualTreeHelper.GetChild(dataGrid1, i) is ScrollViewer)
{
ScrollViewer scroll =
(ScrollViewer)(VisualTreeHelper.GetChild(dataGrid1, i));
Console.WriteLine(scroll.HorizontalOffset);
}
}
请注意,scroll.HorizontalOffset
是只读
只需在XAML中命名基控件(例如ListView),并在代码后面按名称访问它。