Access ScrollView properties of a DataGrid in WPF

后端 未结 2 1303
时光取名叫无心
时光取名叫无心 2021-01-13 12:58

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

Thanks

2条回答
  •  花落未央
    2021-01-13 13:38

    In XAML

     
    

    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

提交回复
热议问题