Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
606 views
Welcome To Ask or Share your Answers For Others

1 Answer

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

<TextBox CommandManager.PreviewExecuted="textBox_PreviewExecuted"
         ContextMenu="{x:Null}" />

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;
     }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...