Click here to Skip to main content
15,884,836 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everybody,
I have a little issue with MouseWheel events in WPF.

I have the following code:
One Custom Controller
XML
<UserControl x:Name="customTileController"
             ...
             MouseDown="MainCanvas_Distribute_MouseDown"
             MouseMove="MainCanvas_Distribute_MouseMove"
             MouseUp="MainCanvas_Distribute_MouseUp"
             MouseWheel="customTileController_MouseWheel">

with this event handler in the code behind:
C#
private void customTileController_MouseWheel(object sender, MouseWheelEventArgs e)
       {
           //for upwards scrolling we zoom in
           if (e.Delta > 0)
           {
               IncreaseZoomLevel();
           }
           //for downwards scrolling we zoom out
           else if (e.Delta < 0)
           {
               DecreaseZoomLevel();
           }
       }


This code works well, when I'm scrolling with one "traditional" mouse (connected via USB, but perhaps it doesn't matter). The problem is, when I try to use the scrollbar thingy on my notebook touchpad, the mouse pointer changes to the scrolling one, but nothing happens in my application. The touchpad is in one fairly old notebook, running Windows 8.1 and it should be connected via PS/2.

Is this issue caused by my code, by WPF (I don't think) or by the old Synaptics driver running under Win8.1?

Thanks for advance and sorry for disturbing you by this tiny issue, but I'm curious what's it caused by :).
Posted
Comments
Sergey Alexandrovich Kryukov 27-May-15 0:39am    
How about scrolling operation using this way in other applications? For example, what happens if you try to scroll this browser page?
The touchpad scrolling function might be simply incorrectly configured...
—SA
macika123 27-May-15 0:46am    
Thanks for your reply!

Well, it varies on application. In Start menu, Firefox, Internet Explorer, Spotify works, but in Visual Studio 2013 doesn't. In Github client neither, but interestingly for a moment it scrolled down a bit...
Sergey Alexandrovich Kryukov 27-May-15 0:52am    
According to your observations, results are inconsistent. I would not take this device seriously then. But you can try to tune it up. Such devices often have manufacturer-specific Control Panel applets with their own UI. Try to find it out and play a bit, and perhaps upgrade the driver and supporting software...
—SA
macika123 27-May-15 2:57am    
Finally, it's working :D . I'm so happy.
After a bit research it seems, that I'm not alone with this problem. Synaptics' virtual scrolling feature is not working in some applications, but in my case the horizontal scrolling is working in Visual Studio (thanks for the tip to dig deeper in touchpad properties, where I found, that I can actually turn horizontal scrolling on).
When I'm listening for messages sent to my WPF application window using Interop, weirdly I receive WM_MOUSEWHEEL messages, even if I'm using virtual scrolling. However, the MouseWheel event still doesn't fire. Fortunately the HIWORD part of wParam is set correctly (at least for my purposes), so I can step zooming in and out based on sheel spin direction.

Now I'm just wondering, that what's this caused by? Basically, the application gets the message, but somehow it's lost in .NET.

Thanks for help and for reassuring, that my code and the error is somewhere else.
Sergey Alexandrovich Kryukov 27-May-15 9:40am    
Please see Solution 1. I think we have to close this question at certain point pretty soon.
If you agree, will you formally accept that answer?

But of course we can continue this discussion if you have some other points or observations...

—SA

1 solution

Basically, my advice is in the discussion in comments to the question.

macika123 wrote:

Finally, it's working :D . I'm so happy.
After a bit research it seems, that I'm not alone with this problem. Synaptics' virtual scrolling feature is not working in some applications, but in my case the horizontal scrolling is working in Visual Studio (thanks for the tip to dig deeper in touchpad properties, where I found, that I can actually turn horizontal scrolling on).
When I'm listening for messages sent to my WPF application window using Interop, weirdly I receive WM_MOUSEWHEEL messages, even if I'm using virtual scrolling. However, the MouseWheel event still doesn't fire. Fortunately the HIWORD part of wParam is set correctly (at least for my purposes), so I can step zooming in and out based on wheel spin direction.

Now I'm just wondering, that what's this caused by? Basically, the application gets the message, but somehow it's lost in .NET.

Thanks for help and for reassuring, that my code and the error is somewhere else.
You are welcome.

Let me put some speculations here. I hope we are about to close this issue, because further steps can be out of our reach.

According to your description, your code does nothing by handling the mouse wheel event (next time, better show where you add the event handler to the invocation tree of some event instance, that is, corresponding += operator, because the method name customTileController_MouseWheel, strictly speaking, does not tell anything about it; also, never use such auto-generated names, they violate good Microsoft naming conventions, for some apparent reasons). It cannot be wrong.

First of all, all input events available in .NET are of different levels. Some are primary and are generated by the hardware and are pushed to the system through the hardware interrupts one some IRQ line and handled by the hardware driver, and some are secondary. For example, hardware events produce KeyDown and KeyUp events (also indirectly), but not KeyPress event, which is secondary to the first two; it comes into play after a long chain taking into account input language, to produce a character which does not exist on lower level.

This is not what happens to physical mouse wheel. When you roll it, hardware generates the event of the same level as, say, mouse move, even though in mouse move of an optical mouse, optical image recognition takes place. Anyway, from the computer standpoint, these are the events of the same level. The roll of the mouse cannot be misinterpreted as mouse move.

What happens in the touchpad "scroll" area? Nothing like that. Instead, some code is just "trying" to emulate the same effect as the "real mouse" does. Physically, the primary events are still the same as you have with the regular touch. Note that even the mouse button down event can be "real" (touchpad has physical buttons, usually) or emulated, through the quick touch and them move. I don't really know where this simulation happens, in some piece of firmware or the driver, but I would rather guess it happens in the driver, that's it, at the expense of the computer's CPU. Some elements of "IA" are involved: recognition of the touch.

And we all know that the recognition can give you false positives and false negatives. And if the quality of the combination of the hardware (including firmware) and the driver is questionable, or some part of it is out of tune, the recognition results can be inadequate. Unfortunately, I failed to explain different results for different software; but it could be timing, the level of CPU load at the moment, anything which tends to confuse low-quality firmware or software… :-) I don't really know consistent experimental results to tell anything more certainly.

—SA
 
Share this answer
 
Comments
macika123 27-May-15 17:09pm    
Thank you for this detailed solution! I'm always stunned how detailed your solutions are. You're awesome ;).

Well, I also think we can close this discussion. My application is now working with both mouse and touchpad and that's what I wanted :) .

Thanks again.
Sergey Alexandrovich Kryukov 27-May-15 18:06pm    
Thank you for your nice words.
You are very welcome. Good luck, call again.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900