dotnet / wpf

WPF is a .NET Core UI framework for building Windows desktop applications.
MIT License
6.92k stars 1.15k forks source link

WPF Mouse Events GetPosition #9243

Open vsfeedback opened 3 weeks ago

vsfeedback commented 3 weeks ago

This issue has been moved from a ticket on Developer Community.


[severity:It bothers me. A fix would be nice] hi, the classes DragEventArgs and MouseEventArgs posses teh same method to retrive the mouse position: "GetPosition(IInputElement)".

It happend in my project, that I had to process the position in Mouse events and drag events. To avoid dublicate code I had the idea to pass the event args to a method, but it wont compile.

How about an interface, which proviedes access to "GetPosition"? chears Michael


Original Comments

Feedback Bot on 4/29/2024, 02:58 PM:

(private comment, text removed)


Original Solutions

(no solutions)

himgoyalmicro commented 3 weeks ago

Can you please share the minimal repro sample for this app?

miloush commented 3 weeks ago

This is practically an API request, you don't need a repro. The author has one method that processes both mouse and drag events, and he needs to call eventArgs.GetPosition in both cases.

The proposed API is something like

public interface IPosition
{
    Point GetPosition(IInputElement relativeTo);
}

and then changing MouseEventArgs, DragEventArgs and presumably also StylusEventArgs to implement IPosition. It could also be implemented by MouseDevice, StylusDevice and IManipulator.

I am not quite convinced the benefit of that is worth the costs.