How to disable Ctrl + V from contextmenu?

2

In the textbox you can not paste, the following code works fine:

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

The problem is showing in the contextmenu when clicking the right mouse:

How to disable Ctrl + V?

    
asked by anonymous 12.06.2018 / 18:13

1 answer

3

Code below hides "Ctrl + V":

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

Result:

Anothercodebelowdisables"Ctrl + V":

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

Result:

    
12.06.2018 / 18:48