Hongjia
Hongjia

Reputation: 73

How can I change the Right-Click menu of a RichTextBlock in UWP

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

Upvotes: 0

Views: 348

Answers (1)

lindexi
lindexi

Reputation: 4357

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

Upvotes: 2

Related Questions