Reputation: 169
I have a WPF RichTextBox and I want to add some more options to the default context menu. I dont want to loose the default menu options (Cut, Copy, Paste). Can you help me out?
Thanks
Upvotes: 4
Views: 4461
Reputation: 61
Extending the previous answer:
<RichTextBox x:Name="rtbTest">
<RichTextBox.ContextMenu>
<ContextMenu>
<MenuItem Command="ApplicationCommands.Cut"/>
<MenuItem Command="ApplicationCommands.Copy"/>
<MenuItem Command="ApplicationCommands.Paste"/>
<MenuItem Header="Custom Item"/>
</ContextMenu>
</RichTextBox.ContextMenu>
</RichTextBox>
Each command is provided with a default UI Text and Key Gesture, by omitting them (in this case the 'Header') from your definition they will fallback to the default, which will be in the users own preferred language.
Upvotes: 6
Reputation: 206
I am afraid that this might be possible or not, but an easy workaround for this(that you might too be aware of) is adding all these application commands back as the context menu item and then adding you custom menu items after that:
<RichTextBox x:Name="rtbTest">
<RichTextBox.ContextMenu>
<ContextMenu>
<MenuItem Header="Cut" Command="ApplicationCommands.Cut"/>
<MenuItem Header="Copy" Command="ApplicationCommands.Copy"/>
<MenuItem Header="Paste" Command="ApplicationCommands.Paste"/>
<MenuItem Header="Custom Item"/>
</ContextMenu>
</RichTextBox.ContextMenu>
</RichTextBox>
This is a workaround but you can easily achieve your purpose using this :)
Upvotes: 2