Reputation: 15
I have a WPF DataGrid. I set the vertical scrollbar's visibility to Hidden -- I want the user to scroll up and down using Button controls that are separate from the Datagrid itself, but I cannot figure out how to access the relevant properties.
I'd also like to do this without code-behind on the view file.
Upvotes: 0
Views: 906
Reputation: 3368
To do it programmatically, you'd need to get to the ScrollViewer
inside, as demonstrated here: Programmatically scrolling WPF 4 DataGrid to end
ScrollViewer GetScrollViewer()
{
if (VisualTreeHelper.GetChildrenCount (this) == 0) return null;
var x = VisualTreeHelper.GetChild (this, 0);
if (x == null) return null;
if (VisualTreeHelper.GetChildrenCount (x) == 0) return null;
return VisualTreeHelper.GetChild (x, 0) as ScrollViewer;
}
Then you could use the ScrollViewer
functions ScrollToHorizontalOffset, ScrollToVerticalOffset.
To control this via XAML, you'd need an attached behavior. Here is a blog post which covers one way to do that: http://blog.scottlogic.com/2010/07/21/exposing-and-binding-to-a-silverlight-scrollviewers-scrollbars.html
Upvotes: 1