2

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

4

1 回答 1

5

您可以禁用 TextBox 的上下文菜单,ContextMenuOpening 事件将为您提供帮助。下面是整个代码。

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;
 }
于 2015-11-24T03:07:03.613 回答