WPF中设置快捷键
方式1:
窗体中加入资源
<UserControl.Resources>
<RoutedUICommand x:Key="Cut" Text="剪切" />
<RoutedUICommand x:Key="Copy" Text="复制" />
<RoutedUICommand x:Key="Paste" Text="粘贴" />
<RoutedUICommand x:Key="Select" Text="全选" />
</UserControl.Resources>
<UserControl.InputBindings>
<KeyBinding Gesture="Ctrl+X" Command="{StaticResource Cut}" />
<KeyBinding Gesture="Ctrl+C" Command="{StaticResource Copy}" />
<KeyBinding Gesture="Ctrl+V" Command="{StaticResource Paste}" />
</UserControl.InputBindings>
<UserControl.CommandBindings>
<CommandBinding Command="{StaticResource Cut}" Executed="CommandBinding_Cut"></CommandBinding>
<CommandBinding Command="{StaticResource Copy}" Executed="CommandBinding_Copy"></CommandBinding>
<CommandBinding Command="{StaticResource Paste}" Executed="CommandBinding_Paste"></CommandBinding>
</UserControl.CommandBindings>
其中:CommandBinding_Cut ,CommandBinding_Copy ,CommandBinding_Paste 是按下快捷键对用的事件操作
private void CommandBinding_Cut(object sender, ExecutedRoutedEventArgs e)
{
}
方式2:
写控件或者窗体的KeyDown事件 PreviewKeyDown="Window_KeyDown"
private void Window_KeyDown(object sender, KeyEventArgs e)
{
try
{
if (e.Key == Key.Enter)
{
//搜索
if (Keyboard.FocusedElement != null && Keyboard.FocusedElement == SearchTxt) Search_Click(SearchBtn, e);
//文件或者文件夹重命名
if (Keyboard.FocusedElement != null && Keyboard.FocusedElement.GetType().Name == "TextBox")
{
TextBox box = Keyboard.FocusedElement as TextBox;
FilesModel model = box.DataContext as FilesModel;
if (model != null) ReName_LostFocus(box, e);
}
Keyboard.ClearFocus();
}
//Ctrl+C 全选
if ((e.KeyboardDevice.IsKeyDown(Key.LeftCtrl) || e.KeyboardDevice.IsKeyDown(Key.RightCtrl)) && e.KeyboardDevice.IsKeyDown(Key.C))
{
if (Keyboard.FocusedElement != null && Keyboard.FocusedElement.GetType().Name == "TextBox") return;
CommandBinding_Copy(null, null);
}
//Ctrl+X 全选
if ((e.KeyboardDevice.IsKeyDown(Key.LeftCtrl) || e.KeyboardDevice.IsKeyDown(Key.RightCtrl)) && e.KeyboardDevice.IsKeyDown(Key.X))
{
if (Keyboard.FocusedElement != null && Keyboard.FocusedElement.GetType().Name == "TextBox") return;
CommandBinding_Cut(null, null);
}
//Ctrl+V 全选
if ((e.KeyboardDevice.IsKeyDown(Key.LeftCtrl) || e.KeyboardDevice.IsKeyDown(Key.RightCtrl)) && e.KeyboardDevice.IsKeyDown(Key.V))
{
if (Keyboard.FocusedElement != null && Keyboard.FocusedElement.GetType().Name == "TextBox") return;
CommandBinding_Paste(null, null);
}
//Ctrl+A 全选
if ((e.KeyboardDevice.IsKeyDown(Key.LeftCtrl) || e.KeyboardDevice.IsKeyDown(Key.RightCtrl)) && e.KeyboardDevice.IsKeyDown(Key.A))
{
SelectAllCheck.IsChecked = true;
SelectAll_Click(SelectAllCheck, e);
}
//Shift+D 删除
if ((e.KeyboardDevice.IsKeyDown(Key.LeftShift) || e.KeyboardDevice.IsKeyDown(Key.RightShift)) && e.KeyboardDevice.IsKeyDown(Key.Delete))
{
DeleteBtn_Click(null, e);
}
}
catch (Exception)
{
}
}
WPF中设置快捷键的更多相关文章
- Web开发中设置快捷键来增强用户体验
从事对日外包一年多以来,发现日本的无论是WinForm项目还是Web项目都注重快捷键的使用,日本人操作的时候都喜欢用键盘而不是用鼠标去点,用他们的话来说"键盘永远比鼠标来的快",所 ...
- wpf中实现快捷键
<Window.InputBindings> <KeyBinding Gesture="Ctrl+Alt+Q" Command="{Binding Yo ...
- WPF中设置了WindowStyle="None"后,窗口仍然有边框的解决方法
1. 设置了窗体的WindowStyle="None",窗口还是右边框,如下图: 2. 这是因为窗体默认是可以改变大小的,所以需要修改ResizeMode的值 ResizeMode ...
- android中设置快捷键方法setShortcut参数的说明
setShortcut之所以要两个参数来设定两个快捷键是为了应对不同的手机键盘.数字快捷键为12键键盘(0~9,*,#,共12个按键)所准备的.其实我怀疑有这种键盘的手机能装Android么?因为我的 ...
- WPF中设置Border的BorderThickness属性会让背景图片产生模糊感
<!--设置BorderThickness会让border的Background图片看起来有模糊感--> <Border x:Name="border" Bord ...
- WPF中的快捷键(累积中)
1. 显示可选属性, ctrl + J 如上图,当不知道Background的可选择时,可以输入 ctrl + J,系统就会显示所有可选属性
- WPF中不规则窗体与WindowsFormsHost控件的兼容问题完美解决方案
首先先得瑟一下,有关WPF中不规则窗体与WindowsFormsHost控件不兼容的问题,网上给出的解决方案不能满足所有的情况,是有特定条件的,比如 WPF中不规则窗体与WebBrowser控件的兼 ...
- 【WPF/WAF】设置快捷键(Shortcut Key)
基于WAF框架:WPF Application Framework (WAF) View层XAML中设置热键. <Window.InputBindings> <!--<KeyB ...
- WPF中通过代码设置控件的坐标
用WPF做贪吃蛇小游戏时,发现了一个问题: 贪吃蛇的移动,我是通过不断刷新Rectangle来实现(贪吃蛇的身体由一组Rectangle组成),因此需要不断调整Rectangle的坐标,但是WPF中没 ...
随机推荐
- PDO多种方式取得查询结果
PDO多种方式取得查询结果 01 December 2009 1:26 Tuesday by Sjolzy PDO最大的特点之一是它的灵活性,本节将介绍如何取得查询结果,包括: 数组(数值或关联数组) ...
- SUSE Linux 13服务器版
SUSE Linux 下面打开图形界面下的终端 桌面右键,选择运行 konsole命令打一桌面终端插件 配置静态ip /etc/sysconfig/network/ 虚拟机下面的网卡 vi /etc/ ...
- MyEclipse中查询
在当前文件中查询: Ctrl + F 在整个项目中查询: Ctrl + H(选File Search)
- EBS R12重启后无法进入登录页面
应用启动正常,但无法进入登录页面: The webpage cannot be found HTTP 404 ... No known changes had been made and the Mi ...
- tiny学习3
这几天在埋头写自己的个星期!而且由于它是基于事件发生的次序(小时就把我的文件导出来了--呵呵.在阅读本文之前,请先看看我Blog里转贴的<TinyXML学习笔记>,相信它能给各位一个关于T ...
- express 手动删除session状态(即登出功能)
在退出按钮被点击后,发送请求/logout,服务端做如下处理: app.get('/logout', function() { delete req.session.user; return res. ...
- PIC32MZ tutorial -- Output Compare
Output Compare is a powerful feature of embedded world. The PIC32 Output Compare module compares the ...
- Shell脚本IF条件判断和判断条件总结
转自:http://m.jb51.net/article/56553.htm 这篇文章主要介绍了Shell脚本IF条件判断和判断条件总结,本文先是给出了IF条件判断的语法,然后给出了常用的判断条件总结 ...
- tomcat的乱码问题
String filename=request.getParameter("filename"); filename=new String(filename.getBytes(&q ...
- Inside The C++ Object Model - 01
前言 1.Foundation项目是一个定义大系统开发模型的项目,又叫Grail. 2.Grail中编译器被分为:parser(语法分析)->type checking -> simpli ...