How to disable Ctrl+V from the contextmenu?

Asked

Viewed 61 times

2

In the textbox you can’t paste at all, the following code works right:

private void Textbox_PreviewExecuted(object sender, ExecutedRoutedEventArgs e)
{
    if (e.Command == ApplicationCommands.Paste)
    {
        e.Handled = true;
    }
}

The problem is showing in the context menu by clicking the right mouse:

inserir a descrição da imagem aqui

How to disable Ctrl+V ?

  • see if it helps: https://stackoverflow.com/q/9632/4713574

  • 1

    @Rovannlinhalis see my answer !

1 answer

3

The following code hides "Ctrl+ V":

<TextBox>
    <TextBox.ContextMenu>
        <ContextMenu>
            <MenuItem Command="ApplicationCommands.Copy" />
            <MenuItem Command="ApplicationCommands.Cut" />
        </ContextMenu>
    </TextBox.ContextMenu>
</TextBox>

Upshot:

inserir a descrição da imagem aqui

Another code to follow, disables "Ctrl+V":

<TextBox>
    <TextBox.ContextMenu>
        <ContextMenu>
            <MenuItem Command="ApplicationCommands.Copy" />
            <MenuItem Command="ApplicationCommands.Cut" />
            <MenuItem Command="ApplicationCommands.Paste" IsEnabled="False" />
        </ContextMenu>
    </TextBox.ContextMenu>
</TextBox>

Upshot:

inserir a descrição da imagem aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.