
We have a SyntaxEditor that uses a custom context menu, like so:
<Window
x:Class="ContextMenuProblem.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:apeditor="clr-namespace:ActiproSoftware.Windows.Controls.SyntaxEditor;assembly=ActiproSoftware.SyntaxEditor.Wpf"
Title="MainWindow"
Height="350"
Width="525"
>
<Grid>
<apeditor:SyntaxEditor
IsDefaultContextMenuEnabled="False"
>
<apeditor:SyntaxEditor.ContextMenu>
<ContextMenu>
<MenuItem
Header="Cut"
Command="apeditor:EditorCommands.CutToClipboard"
InputGestureText="Ctrl+X"
/>
<MenuItem
Header="Copy"
Command="apeditor:EditorCommands.CopyToClipboard"
InputGestureText="Ctrl+C"
/>
<MenuItem
Header="Paste"
Command="apeditor:EditorCommands.PasteFromClipboard"
InputGestureText="Ctrl+V"
/>
<MenuItem
Header="Delete"
Command="apeditor:EditorCommands.Delete"
/>
<Separator
/>
<MenuItem
Header="Select All"
Command="apeditor:EditorCommands.SelectAll"
InputGestureText="Ctrl+A"
/>
</ContextMenu>
</apeditor:SyntaxEditor.ContextMenu>
</apeditor:SyntaxEditor>
</Grid>
</Window>
This works fine for us, except for one problem. When running this, if a user right clicks in the syntax editor (before left clicking - meaning no insertion pointer is present), all the commands are disabled. However ,when I use the built-in context menu and right click first, nearly all commands are enabled.
What can I do to ensure that commands are enabled on the first right click? While I realize overriding CreateDefaultContextMenu is the recommended approach, we prefer to not extend controls whenever possible. I figure I could probably create a behavior that performs a left click on a right click but that seems hacky. I was wondering if there's a better alternative or a workaround.
Thanks,
-Craig