Reputation: 53
I'm working on a Windows 8 Metro app and have a GridView with a few hundred items with different widths displayed. I'm using a VirtualizingStackPanel to help improve memory consumption. I need to scroll an item into the center of the GridView. Using GridView.ScrollIntoView or VirtualizingStackPanel.SetHorizontalOffset will scroll the item to the edge of the screen, not to the center.
This post discusses a similar issue but on the WPF side. The problem is that a) that won't compile for a Metro app as a few of the objects don't exist and b) the implementation for logical scrolling seems to be dependent on the items being equal width.
What is the best solution to this problem? Is there something available in the framework that would make this straightforward?
Upvotes: 4
Views: 1466
Reputation: 15006
ScrollIntoView works, but you need to call it like this:
await Dispatcher.RunAsync(CoreDispatcherPriority.Low,
() => { this.gridView.ScrollIntoView(yourItem); });
Upvotes: 1