0

I want to override the right-click menu in a RichTextBlock or a TextBlock, I have been searching for the solution and tried using RightTappedEvent, but it did not fire when right tapped a chosen text, but it fired when I right tapped in elsewhere in the control.

Right-click Menu

lindexi
  • 4,182
  • 3
  • 19
  • 65
Hongjia
  • 73
  • 6

1 Answers1

2

Yes, you can use ContextFlyout to change it.

You can add the ContextFlyout to custom your menu.

The code shows how to add the custom menu.

    <RichTextBlock HorizontalAlignment="Center" VerticalAlignment="Center">
        <RichTextBlock.ContextFlyout>
            <MenuFlyout>
                <MenuFlyoutItem Text="1" />
                <MenuFlyoutItem Text="2" />
            </MenuFlyout>
        </RichTextBlock.ContextFlyout>
        <Paragraph>Welcome to my blog http://blog.lindexi.com I write some UWP blogs</Paragraph>
    </RichTextBlock>

enter image description here

See UWP How to custom RichTextBlock right click menu

All code is in github

lindexi
  • 4,182
  • 3
  • 19
  • 65
  • 谢谢!Do you know how to show flyout when the text is selected? I have posted another question about that and that is something I want to achieve. So I was thinking maybe I can get answer from this question, but apparently this is not the solution. Thanks anyway, take a look of my another question if you'd like to. [How to show a flyout in where the text in a TextBlock is selected](https://stackoverflow.com/questions/55138073/how-to-show-a-flyout-in-where-the-text-in-a-textblock-is-selected) – Hongjia Mar 22 '19 at 07:45
  • Hey, 原来是来自中国的小伙伴,真担心我的英文太渣。 – lindexi Mar 23 '19 at 01:06