How can you prevent at least one of copy, cut and/or paste actions in a WPF project? Here how prevent these events in a textbox.

XAML:

<TextBox CommandManager.PreviewExecuted="textBox_PreviewExecuted" ></TextBox>

Code behind:

private void textBox_PreviewExecuted(object sender, ExecutedRoutedEventArgs e)
{
    if (e.Command == ApplicationCommands.Copy ||
        e.Command == ApplicationCommands.Cut ||
        e.Command == ApplicationCommands.Paste)
    {
        e.Handled = true;
    }
}
Advertisements