让WPF文本剪切,复制和粘贴限制 [英] Make WPF textbox as cut, copy and paste restricted

查看:2979
本文介绍了让WPF文本剪切,复制和粘贴限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能让一个WPF文本剪切,复制和粘贴限制?

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

推荐答案

剪切,复制和粘贴是常见的命令中使用任何应用程序,

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

这篇关于让WPF文本剪切,复制和粘贴限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆