Skip to content

Commit 6f414b5

Browse files
authored
XPF: Add docs for Ctrl+Click menus on macOS (#660)
This is a new feature that will be added in 1.6.
1 parent 91d7f24 commit 6f414b5

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

xpf/platforms/macos.md

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ However there are problems with this mapping:
1717
2. `ModifierKeys.Windows` is actually [not set in `Keyboard.Modifiers` in WPF](https://github.com/dotnet/wpf/blob/6634719e22053aab8e5e0db37618170494aea334/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/KeyboardDevice.cs#L207-L219)
1818
3. Common controls such as text boxes are expected to have different keyboard shortcuts in macOS, such as "Move the insertion point to the beginning of the previous word" being Option+Left Arrow on macOS instead of Control+Left Arrow
1919

20-
## Automatic macOS Key Mapping
20+
### Automatic macOS Key Mapping
2121

2222
To fix many of these problems, one can call the `XpfKeyboard.MapMacOSKeys()` method on startup. This would usually be done in the same place as [the XPF WinAPI shim setup](../third-party-libraries); that is, in the constructor of your `App` class or `Program.Main`:
2323

@@ -45,6 +45,27 @@ Calling this method on macOS:
4545
- Option+Left Arrow-> Ctrl+Left Arrow
4646
- Option+Left Arrow -> Ctrl+Left Arrow
4747

48-
## Automatic macOS Keyboard Mapping
48+
### macOS Custom Keyboard Mapping
4949

50-
For more flexible key mapping you can [add custom key mappings](../advanced/key-mapping).
50+
For more flexible key mapping you can [add custom key mappings](../advanced/key-mapping).
51+
52+
## Context Menus <MinVersion version="1.6" />
53+
54+
On macOS, context menus can be opened by Ctrl+Clicking as well as by right clicking. You can enable this feature by setting `XpfMouse.ShowContextMenuOnMacOSCtrlClick` on startup. This would usually be done in the same place as [the XPF WinAPI shim setup](../third-party-libraries); that is, in the constructor of your `App` class or `Program.Main`:
55+
56+
```csharp
57+
using System.Windows;
58+
using Atlantis;
59+
60+
namespace XpfKeyboardMappingExample;
61+
62+
public partial class App : Application
63+
{
64+
public App()
65+
{
66+
XpfMouse.ShowContextMenuOnMacOSCtrlClick = true;
67+
}
68+
}
69+
```
70+
71+
Once this feature is enabled, it can be disabled on a per-control basis by handling the [`ContextMenuOpening` event](https://learn.microsoft.com/en-us/dotnet/desktop/wpf/advanced/how-to-handle-the-contextmenuopening-event#suppressing-any-existing-context-menu-and-displaying-no-context-menu) and checking the value of [`Keyboard.Modifiers`](https://learn.microsoft.com/en-us/dotnet/api/system.windows.input.keyboard.modifiers) and/or [`Mouse.LeftButton`](https://learn.microsoft.com/en-us/dotnet/api/system.windows.input.mouse.leftbutton) to determine how the context menu is being opened.

0 commit comments

Comments
 (0)