Make WPF textbox as cut, copy and paste restricted

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

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

2条回答
  •  被撕碎了的回忆
    2020-12-13 19:22

    Cut, Copy and Paste are the common commands used any application,

    
    

    in above textbox code we can restrict these commands in PrviewExecuted event of CommandManager Class

    and in code behind add below code and your job is done

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

提交回复
热议问题