Search code examples
c#gridviewwindows-runtimescrollviewwindows-10-universal

ScrollIntoView property not working for gridview in windows 10 universal app


I tried this below code:

XAML Code:

<GridView x:Name="listgrid">
 <GridView.ItemTemplate>
   <DataTemplate>
     <StackPanel Margin="15,15,0,0">
       <Image Height="170" Width="170" Source="{Binding}"></Image>
     </StackPanel>
   </DataTemplate>
 </GridView.ItemTemplate>

Cs code:

for (int i = 1; i < 50; i++)
{
   list.Add("ms-appx:///Images/A-aa.jpg");
}
listgrid.ItemsSource = list;
listgrid.ScrollIntoView(listgrid.Items[30]);

I above code to scroll view to my selected item, but it's not showing any changes, i think i used this property in a wrong way any one please help me to scroll to gridview position.


Solution

  • I have replied your same question in MSDN: https://social.msdn.microsoft.com/Forums/windowsapps/en-US/d0a772b3-80b9-4a11-92a9-89963c29a52f/scrollintoview-property-not-working-for-gridview-in-windows-10-universal-app?forum=wpdevelop

    You need to have something more to distinguish items, for example, give every image a name since items you bind to GridView are same, ScrollIntoView default find the first one.

    And commonly you need to set a height property for the GridView.

    For more complex requirements, there is a good thread you can reference: Windows 10 ScrollIntoView() is not scrolling to the items in the middle of a listview