James Cadd
James Cadd

Reputation: 12216

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.

Upvotes: 1

Views: 833

Answers (2)

James Cadd
James Cadd

Reputation: 12216

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

Upvotes: 3

Brian P. Hamachek
Brian P. Hamachek

Reputation: 935

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

Upvotes: 4

Related Questions