在 WPF 中访问 DataGrid 的 ScrollView 属性 [英] Access ScrollView properties of a DataGrid in WPF

查看:26
本文介绍了在 WPF 中访问 DataGrid 的 ScrollView 属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以访问我在数据网格的属性列表中找不到的水平偏移量?

Is it possible to access the horizontal offset, which I can't find in the property list of the datagrid ?

谢谢

推荐答案

在 XAML 中

 <DataGrid Name="dataGrid1" ..... />

如果您想访问 Horizo​​ntalOffset,您需要访问包含在 Datagrid 中的 ScrollViewer

If you want to access to the HorizontalOffset you need to access to the ScrollViewer contained inside the Datagrid

访问 ScrollViewer 的一种可能方法是

one possible method to access the ScrollViewer is

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.Horizo​​ntalOffset 是只读的

这篇关于在 WPF 中访问 DataGrid 的 ScrollView 属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆