0

I have created a project in UWP, that has GridView:

<GridView x:Name="gvItems"
        ScrollViewer.HorizontalScrollBarVisibility="Disabled"
        ScrollViewer.HorizontalScrollMode="Disabled"
        ScrollViewer.VerticalScrollBarVisibility="Hidden"
        ScrollViewer.VerticalScrollMode="Enabled"
        VerticalAlignment="Stretch"
        HorizontalAlignment="Stretch"
        ItemTemplate="{StaticResource Template}">
    <GridView.ItemsPanel>
        <ItemsPanelTemplate>
            <ItemsWrapGrid Orientation="Horizontal"/>
        </ItemsPanelTemplate>
    </GridView.ItemsPanel>
</GridView>

The problem is that when I want to scroll into some item I can't because ScrollViewer is not aware of it:

var scrollViewer = gvItems.GetFirstDescendantOfType<ScrollViewer>();
if (scrollViewer == null)
{
    return;
} 

GridViewItem selectedVisual = gvItems.ContainerFromItem(selected) as GridViewItem;
if (selectedVisual == null)
{
    return;
}

scrollViewer.ChangeView(0, scrollViewer.VerticalOffset + (scrollViewer.ViewportHeight / 2), null);

If item is outside of virtualizing list selectedVisual will be NULL always.

Does anyone know how to scroll into items that are not yet being "initialized" in the virtualized list?

And this got nothing to do with "scrolling to the items in the middle of a listview", the problem is that listview is not aware of item and it's not scrolling at all.

user3239349
  • 877
  • 1
  • 12
  • 33
  • Try [this](https://stackoverflow.com/questions/32557216/windows-10-scrollintoview-is-not-scrolling-to-the-items-in-the-middle-of-a-lis). – Justin XL Aug 07 '17 at 22:22
  • 1
    Possible duplicate of [Windows 10 ScrollIntoView() is not scrolling to the items in the middle of a listview](https://stackoverflow.com/questions/32557216/windows-10-scrollintoview-is-not-scrolling-to-the-items-in-the-middle-of-a-lis) – Nico Zhu Aug 09 '17 at 02:11
  • No, this is totally different problem. Here listview is not aware of items and not scrolling at all. – user3239349 Aug 09 '17 at 09:22
  • @user3239349 did you try the the method in my answer? It should work for **both** GridView and ListView. – Justin XL Aug 09 '17 at 09:40

0 Answers0