I would like to add keyboard shortcuts to some buttons. But for some reason the keyboard accelerator triggers the event twice. When I just click the button with the mouse, it works as expected.
<MenuBar>
<MenuBarItem Title="File">
<MenuFlyoutItem Text="Open file..." Click="OnOpen" Icon="OpenFile">
<MenuFlyoutItem.KeyboardAccelerators>
<KeyboardAccelerator Key="O" Modifiers="Control"/>
</MenuFlyoutItem.KeyboardAccelerators>
</MenuFlyoutItem>
</MenuBarItem>
</MenuBar>
FileLoader.LoadFile here shows the FileOpenPicker:
private async void OnOpen(object sender, RoutedEventArgs e)
{
if (!Busy)
{
var loadedFile = await FileLoader.LoadFile(".txt", PickerLocationId.Desktop);
if(loadedFile != null)
{
await FileLoader.LoadTextFile(loadedFile);
}
}
}
The same problem is happening with a FileSavePicker elsewhere in my code.
How can I prevent this from happening?