Make WPF textbox as cut, copy and paste restricted

前端 未结 2 2092
温柔的废话
温柔的废话 2020-12-13 18:53

How can I make a WPF textbox cut, copy and paste restricted?

2条回答
  •  青春惊慌失措
    2020-12-13 19:29

    The commandName method will not work on a System with Japanese OS as the commandName=="Paste" comparision will fail. I tried the following approach and it worked for me. Also I do not need to disable the context menu manually.

    In the XaML file:

    
        
    
    

    In the code behind:

    private void CommandBinding_CanExecutePaste(object sender, CanExecuteRoutedEventArgs e)
    {
        e.CanExecute = false;
        e.Handled = true;
    }
    

提交回复
热议问题