Access ScrollView properties of a DataGrid in WPF

datagrid, vb.net, wpf

Solution

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

Problem

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

Original source