I have a DataGrid from the Silverligt 4.0 SDK. I want to access "HorizontalOffset" from the internal ScrollViewer of the DataGrid. I can access attached properties for it, such as:
<data:DataGrid x:Name="MyGrid"
ItemsSource="{Binding Elements}"
ScrollViewer.HorizontalScrollBarVisibility="Visible">
But how can I access the ScrollViewers HorizontalOffset property? If I could bind it in XAML it would be nice but it could be enough to access it from code behind.
I've tried to find it by iterating the visual tree from the DataGrid in code behind but I can't get hold of it (scroller is always null). I've tried several different implementations of FindVisualChild().
var scroller = MyGrid.FindVisualChild<ScrollViewer>();
It might have something to do with the fact the the
DataGriddoesn't use aScrollViewerThe default template manages its own scrolling and includes the two scroll bars. You therefore need to access the horizontal scroll bar.
I use my own
VisualTreeEnumerationclass the code for which you'll find here.