monitor mousemove event in wpf - wpf

I'm trying to monitor the mouse movement over the application window
so that whenever the mouse moves its coordinates are reflected in two text conrols
Is it possible to do it in XAML only (without code)?

No, you have to write code. Getting mouse position is only doable by calling the Mouse.GetPosition method. This isn't something you can represent in XAML.

Related

How to detect mouse click position in Xamarin.Forms using WPF?

Using Xamarin.Forms with WPF, how do I capture a mouse click event and get the mouse position relative to the clicked element?
I've tried using ClickGestureRecognizer but can't get the event to fire.
<BoxView>
<BoxView.GestureRecognizers>
<ClickGestureRecognizer Clicked="ClickGestureRecognizer_OnClicked" />
</BoxView.GestureRecognizers>
</BoxView>
Perhaps this is not implemented for WPF at this time, or I am using it wrongly. TapGestureRecognizer does fire, but I can't see a way to get the mouse location when using that.

WPF: How to change behavior at runtime?

I'm designing UI in WPF for logic circuit simulator. I want my application to support various behaviors depending on current operation mode like selection mode (rubberband selection), component placing mode, wiring mode, interaction mode etc. I thought about using state pattern in my ViewModel and encapsulating the behaviors in states corresponding to operation modes.
My trouble is reflecting this changes in the View. I want each mode to subscribe to different mouse events (selection is mouse down, mouse move, mouse up; placing is mouse enter, mouse move, mouse leave). Can I encapsulate this in generic behaviors and then somehow switch behaviors at runtime? Should I use attached properties for it? Or maybe custom control? What's the MVVM way of doing this?
Are the different behaviours linked to mouse events only and the XAML of UserControl is always the same?
If the answer is yes then you can implements a single behaviour attached to all mouse events you want to manage in all scenarios and store the current scenario inside a variable of the UserControl.
Doing so, your custom behaviour can decide to call or not to call a particular ICommand, basing on the value of the variable of the UserControl that indicates the current scenario.

How to store the mouse click events in xlib programming

I am using xlib draw a figure and give some events as input to draw certain on the window.I want to know how can i save these events results? Because on window resize all my results disappears.
How can i save the results of each event so that on resize(where it calls the expose event) the results of previous events remains on the screen.
As I remember xlib if you loose content of the window when resizing it means you didn't register your callback for refresh event. Copy your drawing code into this callback and everything should be ok.

What does it mean to "Capture the mouse" in WPF?

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.

WPF MouseMove Event Polling

I've created a WPF application where the title bar and chrome are turned off. I have a border around the entire app, with the idea that it would act like the chrome in some regards. The first thing I'm trying to do is have the mousemove event capture the movement of the mouse when the mouse is clicked, so that the window moves with the mouse. The problem is that if the mouse moves too quickly, it manages to leave the window and therefore the mousemove no longer fires. I've been able to do this with a normal WinForm with no problems regardless of the speed of the mouse. Is there any way to do this more efficiently, or perhaps tune the polling of the mousemove? Perhaps a different container other than border that would perform better?
Try Me.DragMove in the window's left click event handler. It much better than most custom solutions.
When the user clicks you should capture the mouse (see Mouse.Capture). That way, you'll get the mouse events regardless of whether the mouse cursor is over your element or not.

Resources