3

我有一个 WPF RichTextBox,我想在默认上下文菜单中添加更多选项。我不想放弃默认菜单选项(剪切、复制、粘贴)。你能帮我吗?

谢谢

4

2 回答 2

4

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.

于 2013-12-06T09:46:37.237 回答
2

恐怕这可能或不可能,但一个简单的解决方法(您可能也知道)是将所有这些应用程序命令添加回上下文菜单项,然后在此之后添加自定义菜单项:

<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>

这是一种解决方法,但您可以使用它轻松实现您的目的:)

于 2013-02-19T12:18:08.863 回答