WPF Touch/Panning Scroll Event Handler - c#

For C# WPF, there is a event handler MouseWheel for scrolling using mouse wheel. Is there any similar event handler for scrolling using touch/panning?

If you are using a ScrollViewer and you have touch hardware (which causes manipulation events to occur), then you can use the PanningMode property.
https://msdn.microsoft.com/en-us/library/system.windows.controls.scrollviewer.panningmode(v=vs.110).aspx
If you don't have touch hardware, and you want the mouse to be used for panning, then you can add some additional behaviour to a ScrollViewer to support that.
Can i scroll an ItemsControl by dragging row items instead of scrollbar
If you want a normal mouse to be able to generate cause "manipulation" events to occur (i.e. simulate a touch device)....then you can use the MultiTouch SDK to provide a new device that will map mouse events to touch ones - something you don't normally get.
https://blogs.msdn.microsoft.com/ansont/2010/01/30/custom-touch-devices/
How do I Emulate touch events without using touch screen
WPF: Is there a possibility to "route" ordinary mouse events to touch events in Windows 7
If you have want to handle manipulation events (via real touch hardware, or the simulated one via MultiTouch SDK), and have PanningMode work at the same time on the ScrollViewer...use this.
Manipulation event and panning mode

Related

C# WPF - MouseLeftUp Event doesn't appear to fire [duplicate]

On System.Windows.UIElement there is a CaptureMouse() and a paired ReleaseMouseCapture() method. In this WPF DragDrop sample they call CaptureMouse on MouseDown and release it on MouseUp. The documentation in MSDN is about as useless as it comes - "CaptureMouse -> Captures the mouse."
In my head before trying it I assumed that it somehow locked the mouse inside the UIElement bounds, but that's clearly not the case when I try it. From experimenting, it seems to have something to do with responding to events when the mouse is outside of the UIElement, but not wanting to be a cargo cult programmer I don't want to just use it because the example does, I'd like an authoritative description of what it means.
From Capture and Uncapture the Mouse on MSDN:
When an object captures the mouse, all mouse related events are treated as if the object with mouse capture perform the event, even if the mouse pointer is over another object.
Only the capturing control receives the mouse events until released.
Capturing the mouse is useful for dragging because all the dragging code can exist in the one control, rather than being spread over multiple controls.
When it has captured the mouse, a control will receive mouse events even if the mouse pointer is no longer within its bounding area.
Typically, it's used for:
Drag and drop
Buttons (to handle Mouse Up when you put the mouse down on the button and move the mouse before you release the button)
The Silverlight 2 documentation for it has a more verbose description, I don't know why it isn't a part of the 3.5 documentation page too:
When an object has captured the mouse, that object receives mouse input whether or not the mouse pointer is within its bounding area. The mouse is typically only captured during simulated drag operations.
...
It works the same with WPF, and so the reason it is used with DragDrop, is that is how the
it knows to report back to the control being dragged from when the mouse may be outside of that control. If you comment out the MyCanvas.Capture() and the Capture(Null) (which clears it) then you can no longer drop.

Blocking sending events from child to parent

I have very short contact with the C# and WPF, although most of the stuff I could find over the Internet. However, I cannot find anything (or don't know how to request google to find it) about blocking sending events to the parent.
I've got an Image inside ScrollViewer. My point is to create zooming option for the image by using Ctrl + mouse wheel, but obviously the scrollbars of the ScrollViewer are moving while I am moving mouse wheel (the mouse wheel method is defined within the Image). Is there any possibility to block event sent from child to parent when Ctrl is down?
In your handler for the Image, you should set the event's Handled property to true when Ctrl is pressed. This will prevent the ScrollViewer from handling the mouse wheel event.
See http://msdn.microsoft.com/en-us/library/ms742806.aspx for more information, especially the section entitled "The Concept of Handled."

Detect when interial scrolling begins WinRT XAML

Someone I've been banging my head around - is there a way to detect when intertial scrolling begins on a scrollviewer in WinRT's XAML model in a touch input scerario, no matter how round abouts it is?
I've tried listening to PointerUp & Down's & Released & Move events on UI elements and on the CoreWindow object itself and none of them fire after the scrollviewer starts moving (so it seems the scrollviewer is eating the pointer moved events before the application Window even recieves them? What fun DirectInput is...)? And of course overlaying something on top the of scrollviewer that catches events and then says it hasn't handled them simply doesn't work (I'm guessing a side effect of DirectInput again). So is there a way to do, without writing my own panel?
(I've been tasked to write a flipview like control where the items scale / zoom up as they become the active item - and it looks horrible to only fire it on the selection changed event).

Inject/simulate WPF routed mouse click events

I have some straight WPF 3.5 controls handling left mouse clicks that I need to use within a Surface app (SDK 1.0). The problem I am facing is that do not work by default. I am thinking of wrapping each control in a SurfaceContentControl and translating ContactTouchDown or ContactTapGesture events to corresponding MouseDown events.
The problem boils down to - how to "inject" or simulate arbitrary routed mouse events? I have tried InputManager.Current.ProcessInput() but didn't get very far. Any help is appreciated.
Try to use AutomationPeer classes. For example ButtonAutomationPeer is for Button. The code below initiates a click.
ButtonAutomationPeer peer = new ButtonAutomationPeer(button);
IInvokeProvider provider = (IInvokeProvider)peer.GetPattern(PatternInterface.Invoke);
provider.Invoke();
evpo's idea is an interesting one (though if you're working with custom controls, they rarely come with AutomationPeer classes).
You can't simply 'inject' mouse input by sending WM_MOUSE* events to your app... WPF would indeed process the message but when it goes to figure out the position of mouse for that event, it will query the actual mouse API instead of trying what you stick in the WM.
So really all you can do is tell windows to move the actual mouse cursor and act as though the button is being clicked/released. Some code you can use for that is in http://www.codeproject.com/KB/system/globalmousekeyboardlib.aspx
That said, while you can technically do this, it sucks... you've got an expensive multitouch device but are 1) showing a mouse cursor on it 2) limiting arbitrary parts of it to being used 'single touch' (and only one of those arbitrary parts at a time and 3) coming up with an arbitrary method of determining which finger you will treat as the mouse-controlling one

Global mouse events

Hallo,
I am trying to keep track of the mouse position and also its delta position. Is there any nicer way of doing this then implementing all the mouse events for all my forms in my window?
The problem with using the MouseMove event is that as soon as the mouse moves outside of the form it stops working properly. Implementing the mouseEnter, mouseLeave improves it somewhat, but it does still not feel perfect. Any ideas?
Regards,
You have to handle lower level windows events.
Check out this example: http://www.codeproject.com/KB/cs/globalhook.aspx

Categories

Resources