question

IDGO-6443 avatar image
0 Votes"
IDGO-6443 asked ·

UWP - ListBox Scroll Mouse Released Event not Found

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.



windows-uwpwindows-uwp-xaml
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

NicoZhu-MSFT avatar image
0 Votes"
NicoZhu-MSFT answered ·

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");
     }
 }


· 2 · Share
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I Tried this already......The Problem occurs when I dont use ScrollView ,i.e I use Mousewheel to scroll it does skip 2 or 3 Items in the OnScreenVisiblity Items.

To reproduce this, U can use Mousewheel and attempt fast Mouse wheel (Scroll - Release Multiple Times little Fast)

Is there any other way I can solve

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.

0 Votes 0 · ·

As the answer said, ScrollBar's PointerReleased was handled internally. currently there is not good way to detect it. if you do want this feature please feel free post with Windows Feed back hub app.

0 Votes 0 · ·
MikeCriderMSFT-6097 avatar image
1 Vote"
MikeCriderMSFT-6097 answered ·

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.

· Share
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.