microsoft / microsoft/microsoft-ui-xaml
When app overrides "TextControlCommandBarContextFlyout" with a custom flyout, the KeyboardAccelerators in the flyout aren't respected
- Dominant language
- C++
- Stars
- 8.4k
- Forks
- 942
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 105
Description
### Describe the bug
I added this to my blank C# WinUI3 app:
```
protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
{
var m = new MenuFlyout();
m.Items.Add(new MenuFlyoutItem() { Text = "Dummy item 1" });
m.Items.Add(new MenuFlyoutItem() { Text = "Hello World" });
var ka = new KeyboardAccelerator()
{
Key = Windows.System.VirtualKey.H,
Modifiers = Windows.System.VirtualKeyModifiers.Control
};
ka.Invoked += KeyboardAccelerator_Invoked;
m.Items[1].KeyboardAccelerators.Add(ka);
Resources["TextControlCommandBarContextFlyout"] = m;
```
Expected: Pressing ctrl+h will cause KeyboardAccelerator_Invoked to get called.
Observed: It's not called.
I believe this works in System Xaml / UWP / CoreWindow, and that this problem is specific to islands and WinUI3 (which uses only islands).
### Why is this important?
This is not for an important scenario, I've filed it mostly for tracking.
### Steps to reproduce the bug
I added this to my blank C# WinUI3 app:
```
protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
{
var m = new MenuFlyout();
m.Items.Add(new MenuFlyoutItem() { Text = "Dummy item 1" });
m.Items.Add(new MenuFlyoutItem() { Text = "Hello World" });
var ka = new KeyboardAccelerator()
{
Key = Windows.System.VirtualKey.H,
Modifiers = Windows.System.VirtualKeyModifiers.Control
};
ka.Invoked += KeyboardAccelerator_Invoked;
m.Items[1].KeyboardAccelerators.Add(ka);
Resources["TextControlCommandBarContextFlyout"] = m;
```
### Actual behavior
Event is not raised and KeyboardAccelerator_Invoked is not called.
### Expected behavior
KeyboardAccelerator_Invoked should be called.
### Screenshots
_No response_
### NuGet package version
None
### Windows version
_No response_
### Additional context
_No response_
Contributor guide
Research direction
Start with the OnLaunched reproduction in the issue and trace how a custom TextControlCommandBarContextFlyout handles KeyboardAccelerators in a WinUI 3 desktop app. Compare the expected Ctrl+H behavior with the observed missing KeyboardAccelerator_Invoked call; done means the callback is raised for the custom flyout.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- desktop
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100