How to determine when ScrollViewer started scrolling? - c#

I'm using a Windows Phone 8.1 project and have a ScrollViewer in my XAML.
Is there an event which will fire when the ScrollViewer start scrolling? Or anyway to trigger code when ScrollViewer start scrolling?

Try ViewChanging and ViewChanged events of ScrollViewer.
Note that these events will be called multiple times during a touch manipulation. You will need to rely on IsIntermediate (in ScrollViewerViewChangedEventArgs) or IsInertial (in ScrollViewerViewChangingEventArgs) to call your code accordingly.
Update
If you want to know when a touch happens immediately I'd give the ScrollViewer's direct child, for example, a StackPanel a transparent background and then subscribe to its PointerEntered event.

Related

WPF ScrollViewer Changed Event fired automatically

As per requirement need in C# WPF application , We want to load Data on scrollViewer while moving Horizontal scroll bar.
As we have tried by scrollViewer_ScrollChanged event. But It fired automatically every time while loading of scrollViewer.
In our case we have one grid control inside scrollViewer.
Please help me, looking for positive reply.

Why ScrollViewer fired PointerCaptureLost when starting scroll?

In my Windows Store App (c#, xaml) I have ScrollViewer, when I zoom in it and trying to scroll - the ScrollViewer fired event PointerCaptureLost and I can't handle any pointers events anymore.
Why it happens, and how I can handle pointers events (for example PointerMoved) during scroll ScrollViewer?
Looks like it may not be possible without some serious hacks.
What's happening is that whenever there is "a touch event that causes the FlipView to animate ", the thing that is causing that animation is the ScrollViewer built into the FlipView, used for flipping. The scrollviewer takes away pointer input until the panning has completed and it cannot be taken back. This is a feature called DirectManipulation which is now processing input on a separate thread to give the smoothest possible panning handling. (Pointer events fire in the UI Thread)*
in http://social.msdn.microsoft.com/Forums/windowsapps/en-US/1e6732d3-0457-4ddc-b762-963ab974491c/pointerreleased-and-flipview

Scroll event for Windows Phone ScrollViewer

In my Windows Phone 8 application I am trying to implement a custom control that behaves like the built-in calendar control which displays the current date above the scrollable content (daily views). Initially I have tried to use the LongListSelector control (which gives me the hierarchical view), but I am not able to determine the scroll position and therefore cannot update the header (the date in the case of the calendar control).
So I switched to using a ScrollViewer control which contains a StackPanel with different controls inside.
Whenever the user scrolls the content I would like to be notified so I can update the UI relative to the content being shown. However, the ScrollViewer doesn't have any explicit scrolling events.
I have tried to use the LayoutUpdated event (which seems to get called frequently enough for my purposes), but when I then update the UI in the event handler another LayoutUpdated event is raised and an infinite loop is created.
How can I update the UI based on the scroll position?
I have no idea, But check this links, this may help.
Get scroll event for ScrollViewer on Windows Phone
http://social.msdn.microsoft.com/Forums/silverlight/en-US/b1cdf697-ed37-4d3a-9f3c-46338bdc92b4/how-to-get-a-scroll-event-from-a-scrollviewer?forum=silverlightbugs

Possible to handle all MouseMove events in WP7.1?

Is it possible to get notification of any MouseMove event, even those marked as handled? I have the following Xaml:
<Grid x:Name="ParentContainer">
<ScrollViewer>
...
</ScrollViewer>
</Grid>
My goal is to get all MouseMove events on the ScrollViewer, or something reasonably close to it like the ParentContainer, without resorting to setting ManipulationMode="Control" on the ScrollViewer for the best possible performance.
Handling MouseMove on the ParentContainer (or the ScrollViewer) works when ManipulationMode="Control" is set on the ScrollViewer, but not when ManipulationMode="System". It sounds like to improve performance in Mango, the ScrollViewer started swallowing MouseMove events to improve performance. However, I'd expect to be able to get those handled events as follows:
ParentContainer.AddHandler(???.MouseMoveEvent, MyMouseMoveHandler, true);
In Silverlight or WPF I would expect that code to route all mouse events to MyMouseMoveHandler, even handled events. Unfortunately I can't find a static definition of MouseMoveEvent to pass to AddHandler.
Has anyone had success using AddHandler with MouseMoveEvent in WP7?
My last resort may be to add an overlay on top of the ScrollViewer with Background="Transparent" that would capture all Mouse events, but not mark them as handled and see if they propagate down to the ScrollViewer.
In Windows Phone OS 7.1, changes were made to specifically improve the scrolling of the ScrollViewer control. To do this they had to move the listening of the touch gestures to a separate thread. This meant an architecture level change for how the control listened to the gestures. With Windows Phone 7.1, there is now 3 threads responsible for scrolling the ScrollViewer: one for input, one for animations, and one for creating new items.
As a result of this change, you will not be able to capture the handled mouse events from this control, unless you set the ManipulationMode to Control. As you stated in your question though, this will disable the changes which were made to improve scrolling performance.
You cannot expect that a solution which will work for non-Windows Phone Silverlight will work in this case because the underlying architecture is fundamentally different on the phone starting with Windows Phone 7.1.
Here is Microsoft's blog post regarding the change: http://blogs.msdn.com/b/slmperf/archive/2011/06/02/listbox-scrollviewer-performance-improvement-for-mango-and-how-it-impacts-your-existing-application.aspx
Instead of looking for mouse events it's possible to use the Touch.FrameReported event to receive notification any time the user touches the screen. This event reports for ScrollViewers where the ManipulationMode == System. This seems to be a suitable workaround for a global MouseMove handler on WP7.
http://msdn.microsoft.com/en-us/library/system.windows.input.touch.framereported(v=vs.95).aspx

Mouse wheel not working when over ScrollViewer's child controls

I was kind of expecting my ScrollViewer's child controls to hand the MouseWheel events back up the the ScrollViewer automatically, and that's not the case.
I have a ScrollViewer with a ListBox in it. If I manually resize the width of the ListBox to be less than the ScrollViewer, the MouseWheel works on all of the ScrollViewer but has no effect when the mouse is positioned above the ListBox.
What's the standard way to do this? Do I put an event trigger on the ListBox that fires the event on the parent? Do I handle and reroute the event in the code behind?
The ListBox's template has a ScrollViewer in it, so that ScrollViewer will be handling the events and stopping them from propagating up the visual tree.
What exactly are you trying to achieve by having a ListBox inside a ScrollViewer? Perhaps you need to re-template the ListBox, but it's impossible to say without further info.

Categories