访问WPF中DataGrid的ScrollView属性 [英] Access ScrollView properties of a DataGrid in WPF
本文介绍了访问WPF中DataGrid的ScrollView属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以访问在datagrid的属性列表中找不到的水平偏移?
谢谢
解决方案
在XAML中
< DataGrid Name =dataGrid1 ..... />
如果要访问HorizontalOffset,您需要访问包含在Datagrid中的ScrollViewer
访问ScrollViewer的一种可能的方法是
for(int i = 0; i< VisualTreeHelper.GetChildrenCount(dataGrid1); i ++)
{
if(VisualTreeHelper.GetChild(dataGrid1,i)是ScrollViewer)
{
ScrollViewer scroll =
(ScrollViewer)(VisualTreeHelper.GetChild(dataGrid1,i));
Console.WriteLine(scroll.HorizontalOffset);
}
}
请注意 scroll.HorizontalOffset
是只读
Is it possible to access the horizontal offset, which I can't find in the property list of the datagrid ?
Thanks
解决方案
In XAML
<DataGrid Name="dataGrid1" ..... />
If you want to access to the HorizontalOffset you need to access to the ScrollViewer contained inside the Datagrid
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);
}
}
Note that scroll.HorizontalOffset
is read-only
这篇关于访问WPF中DataGrid的ScrollView属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文