Open mat1jaczyyy opened 4 years ago
KeyModifiers should be passed with the event. There is no guarantee that some static property value has any correlation with particular event instance, so WPF way is a bad API design.
Is this resolved via https://github.com/AvaloniaUI/Avalonia/commit/f0e154ac90299e6f46ff280bb920353454a7f345?
I'm using MVVM architecture so I'm wondering if there is a way to check for a modifier key when executing the Command
on a Button
@derekantrican I don't see if any properties were added to Click event EventArgs.
For MVVM you can use "Avalonia Behavior SDK" (example but UWP). You can also create custom behaviors.
But personally I don't like idea of "0 code in the code behind", because it isn't what MVVM is about. And I believe it is fine to use code behind for View-only logic (including UI-event handlers with its filtering).
Note that I was able to do this thanks to @wieslawsoltes 's sample code on https://github.com/wieslawsoltes/AvaloniaBehaviors/issues/73
KeyModifiers should be passed with the event. There is no guarantee that some static property value has any correlation with particular event instance, so WPF way is a bad API design.
That's not a good api design, but it's very useful and easy to avoid some weird bugs. I have seen that in some cases, it is achieved by paying attention to the KeyDown and KeyUp events, but in many cases, if the control does not get the focus, they cannot get the message notification, so a series of problems will arise.
Example use case: we want slightly different behavior when the user Ctrl+clicks a Button rather than just clicking it without holding a modifier key. Since Click event is raised when keyboard is used to trigger the Button as well, hacking around this with pointer and key events causes a lot of boilerplate code for little reason.
In WPF this is trivial to check for in any piece of code.