horizontal offset for scrollviewer in gridview C#

2019-02-14 15:01发布

问题:

I'm developing metro app using Windows 8 release preview and C#(VS 2012), Is there any way to scroll grid view horizontal scroll bar by providing HorizantalOffset. Brief: In scroll-viewer class we can move horizontal scroll bar and vertical scroll bar dynamically using ScrollToHorizontalOffset and ScrollToVerticalOffset,But in gridview I don't find those properties, So how can I scroll dynamically by code? or can i get reference to scrollbar in gridview ? Can any one help me with this, Thanks in advance

回答1:

You can get the reference to the ScrollViewer from the GridView's template using VisualTreeHelper. You can also use some helper methods I put in WinRT XAML Toolkit - in VisualTreeHelperExtensions. You would just need to add

using WinRTXamlToolkit.Extensions;

then call

var scrollViewer = myGridView.GetFirstDescendantOfType<ScrollViewer>()

and there you go.

EDIT* - note the namespace has changed in later versions of the toolkit to WinRTXamlToolkit.Controls.Extensions.