Search code examples
c#textboxuwpflyoutwindows-10-universal

How can I remove the default "Paste" context menu entry of a TextBox control in a Windows 10 UWP app?


I am building a small UWP app in C#, to scan EAN barcodes and assigning descriptions to it.

The default action when I click on my textboxes is to start speech recognition. And I want the textbox to go into manual editing mode, when I rightclick it (long tap on touch-devices).

Therefore I'd like to remove the default context-menu for my TextBox control. I know how to do this in Windows Forms applications (just add an empty TextBox.ContextMenu with visibility=Collapsed).

Can somebody here help me please, and tell me how to remove the default "Paste" context menu (or "flyout") entry from my textboxes? Is this even possible?

Screenshot: UWP default Textbox context menu


Solution

  • You can to disable context menu of TextBox, ContextMenuOpening event will help you. Below is the whole code.

    XAML:
    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
            <TextBox x:Name="textBox" Text="test" Height="80" Width="100"  ContextMenuOpening="TextBox_ContextMenuOpening" />
    </Grid>
    
    C#:
     private void TextBox_ContextMenuOpening(object sender, ContextMenuEventArgs e)
     {
           e.Handled = true;
     }