Hi IMOsiris,
I'm using the following code in the Loaded event of the page. The GridView is scrolled to the selected item properly. Note that you need to have the exact item from the data source collection of the GridView. I obtain the item by quering the data source:
// MyViewModel is a type of your item.
// MyViewModel must have an ID property serving as a primary key.
// myCollection is the data source collection for your GridView.
// selectedId is an ID of a selected item you want to scroll to.
// Grab the selected item from the collection.
MyViewModel selectedItem = myCollection.Where(it => it.ID == selectedId).FirstOrDefault();
if (selectedItem != null)
{
await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
{
MyGridView.UpdateLayout();
MyGridView.ScrollIntoView(selectedItem);
});
}
Leszek
No comments:
Post a Comment