2

I have a context menu in WPF with, say, 40 menu items. I limited the height of the context menu to, say "130" so that only five item appear at a time. It perfectly automatically assigned scrollviewer which a user can use to scroll the items. In the mean time, I need to capture ScrollChanged event so that I could remember the last scroll position and assign it later. ScrollViewer in

does not have anything I could use for that purpose

1 Answers1

0

You can check the VerticalOffset. The VerticalOffset property is between 0 and ScrollableHeight. Read more about it here.

private void OnScrollChanged(object sender, ScrollChangedEventArgs e)
{
   var scrollViewer = (ScrollViewer)sender;
   if (scrollViewer.VerticalOffset == 0)
          MessageBox.Show("This is the start.");
   else if (scrollViewer.VerticalOffset == scrollViewer.ScrollableHeight)
          MessageBox.Show("This is the end"); 
}

Similar solution here.

Community
  • 1
  • 1
AzzamAziz
  • 2,144
  • 1
  • 24
  • 34