How to suppress cut, copy and paste operations in a TextBox in WPF?

I want to suppress the Cut, Copy, and Paste operations in the text box.

I do not want the user to perform any of these operations using the keyboard or the default context menu in the text box.

Please let me know how can I limit these operations?

+5
source share
1 answer

, CommandManager.PreviewCanExecute. XAML TextBox. CTL + V .., , , , , .

<TextBox CommandManager.PreviewCanExecute="HandleCanExecute" />

, , HandleCanExecute, .

private void HandleCanExecute(object sender, CanExecuteRoutedEventArgs e) {

    if ( e.Command == ApplicationCommands.Cut ||
         e.Command == ApplicationCommands.Copy ||
         e.Command == ApplicationCommands.Paste ) {

        e.CanExecute = false;
        e.Handled = true;

    }

}
+8

All Articles