0

I'm using ScrollViewers inside NavigationViewItems, and I need choose next item after ending of scrollview automatically. I tried to find scroll ending event in docs, but I doesn't find it. Can you help me with it? How I can catch ScrollViewer ending for item changing?

  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Oct 03 '22 at 11:44

1 Answers1

0

Let's say you have a simple navigation.

<NavigationView>
    <NavigationView.MenuItems>
        <NavigationViewItem
            Content="A"
            Tag="PageA" />
        <NavigationViewItem
            Content="B"
            Tag="PageB" />
    </NavigationView.MenuItems>
    <ScrollViewer
        x:Name="ContentScrollViewer"
        ViewChanged="ScrollViewer_ViewChanged">
        <Frame x:Name="ContentFrame" />
    </ScrollViewer>
</NavigationView>

Then you can use the ViewChangedEvent like this.

private void ScrollViewer_ViewChanged(object sender, ScrollViewerViewChangedEventArgs e)
{
    if (sender is ScrollViewer scrollViewer)
    {
        if (this.ContentFrame.Content is PageA &&
            scrollViewer.VerticalOffset == scrollViewer.ScrollableHeight)
        {
            // Navigate to Page B
        }
        else if (this.ContentFrame.Content is PageB &&
            scrollViewer.VerticalOffset == 0)
        {
            // Navigate to Page A
        }
    }
}
Andrew KeepCoding
  • 7,040
  • 2
  • 14
  • 21