简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM