UWP - ListBox Scroll Mouse Released Event not Found

Indudhar Gowda 426 Reputation points
2020-08-24T08:51:22.657+00:00

UWP - ListBox Scroll Mouse Released Event not Found

I have Simple Listbox Inside a Grid ...ScrollBar is working fine, But I need a Event to Raise when ScrollBar Mouse Released Event.

I dont want external ScrollViewer,

Requirement. : Their are 2 ways to scroll

  1. Drag : I need a Event to Raise which ScrollBar Mouse Released Event.
  2. Scroll Down Event to Raise.

I tried ViewChanged, But the Problem is Performance Issue, has it enter's Multiple Times and my data is Huge.

Universal Windows Platform (UWP)
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. MikeCrider-MSFT 6 Reputation points
    2020-09-10T23:27:05.13+00:00

    The ScrollBar control, like many other controls which respond to pointer input, marks PointerReleased as Handled=true to prevent ancestor elements from also responding to that input. (For example, if you have a Button inside of a Button, you probably want clicking the embedded button to only fire the Click event on that button, not on both buttons. Marking the PointerReleased as Handled=true is key to controlling this behavior.)

    Because of this, if you register for the PointerReleased event in the normal way on the ScrollBar or an ancestor, you won't receive the event -- the event has already been handled.

    There is a solution to this, which is to use AddHandler() with handledEventsToo=true. This registers to receive the event even if someone has already marked the event as Handled=true. Here is an example of this call:
    myTargetElement.AddHandler(UIElement.PointerReleasedEvent, new PointerEventHandler(ScrollBar_PointerReleased), true/handledEventsToo/);

    Of course, when registering with handledEventsToo=true, you need to consider the comments above about why this is not the normal behavior. Usually this means you need to call AddHandler on an element which is sufficiently close to the element you are interested in to make sure your handler doesn't get events which you aren't interested in. You can also use the PointerRoutedEventArgs.OriginalSource to check which element originally received the event, though with that you'll likely need to walk up the parent chain to find which control (like the ScrollBar) the element is part of.

    1 person found this answer helpful.
    0 comments No comments

  2. Nico Zhu (Shanghai Wicresoft Co,.Ltd.) 12,856 Reputation points
    2020-08-24T12:03:47.157+00:00

    UWP - ListBox Scroll Mouse Released Event not Found

    I'm afraid you can't detect ScrollBar's PointerReleased directly, because it was handled internally. Currently this a way could detect point release, you could listen internal ScrollViewer 's ViewChanged like the following. And please don't afraid the performance problem.

    private void ScrollViewer_ViewChanged(object sender, ScrollViewerViewChangedEventArgs e)
    {
        if (e.IsIntermediate)
        {
            System.Diagnostics.Debug.WriteLine("scrolling");
        }
        else
        {
            System.Diagnostics.Debug.WriteLine("scroll finish");
        }
    }