XAML: MouseBinding with MouseAction does not work if a keyboard modifier is hold down
- Dominant language
- C#
- Stars
- 7.7k
- Forks
- 1.3k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 61
Description
* .NET Core Version: 6.0
* Windows version: Windows 11
* Does the bug reproduce also in WPF for .NET Framework 4.8?: No idea
**Problem description:**
Binding a command in XAML using `MouseBinding` with only `MouseAction` is not executed when the user holds down SHIFT or CTRL key while clicking on it. This is a problem if we want to check for these modifier keys and execute different code in our command based on whether SHIFT or CTRL or no modifier key is hold down but within the same command.
**Actual behavior:**
The command is not executed
**Expected behavior:**
The command should be executed. For reference a KeyBinding for example is executed even if a mouse button is hold down. Mouse and Key bindings should work independently.
** Additional Info:**
I'm aware of `Gesture` [property](https://docs.microsoft.com/en-us/dotnet/api/system.windows.input.mousebinding?view=windowsdesktop-6.0#examples) where Shift/Ctrl **have to** be used. But I think that if only `MouseAction` is used it should work on all modifier key scenarios. And instead if a developer wants to execute two different commands the `Gesture` property should be used.
**Minimal repro:**
```XAML
```
```C#
public RelayCommand MyCommand => new(a =>
{
if (Keyboard.IsKeyDown(Key.LeftCtrl))
MessageBox.Show("Hey");
else if (Keyboard.IsKeyDown(Key.LeftShift))
MessageBox.Show("Nay");
else
MessageBox.Show("Okay");
});
```
Contributor guide
Assessment
This issue has not been assessed yet.