c# - 如何在 UWP 中使用 TextBox 的 KeyDown 事件捕获 Ctrl-V 或启用右键单击粘贴选项
问题描述
我正在尝试在用户按下 Ctrl + V 快捷方式或右键单击并选择粘贴选项时将图像粘贴到 TextBox 中。我尝试了这种方法来捕获键盘键,但它只有在我输入 V 时才有效
if(e.Key == Windows.System.VirtualKey.V)
如何捕获 Ctrl + V 两个键盘键。就我而言,这不起作用
if (e.Key == Windows.System.VirtualKey.V && e.Key == Windows.System.VirtualKey.Control)
解决方案
为了捕获控制键,您需要检查HasFlag
属性。
var controlDown = Window.Current.CoreWindow.GetKeyState(VirtualKey.Control).HasFlag(CoreVirtualKeyStates.Down);
if (controlDown & e.Key == Windows.System.VirtualKey.V)
{
}
推荐阅读
- database - 如何恢复 Pervasive Db 备份?
- c# - 如何在全选的文本框中写入多个键符号?
- python - while循环的文本表达式在python中不起作用
- javascript - 如何在对象上设置 useState 数据
- javascript - 当它们达到 60 时,我怎样才能将秒数重置为 0
- css - html body 元素的最小高度
- embedded-linux - 无法升级 Yocto Krogoth 中元层的配方
- r - 我已经编写了一个函数,并试图通过 lapply 将其传递给数据框中的每一行
- active-directory - 有没有办法在 DistinguishedName 中排序
- c# - asp.net 核心通过 ENV 变量覆盖连接字符串