WPF菜单快捷方式怎么设置
2013-01-30 11:04
274 查看
参考:http://stackoverflow.com/questions/1361350/keyboard-shortcuts-in-wpf
参考:http://stackoverflow.com/questions/4682915/defining-menuitem-shortcuts
You need to use
you (re)use
for that inthe controls where the shortcuts should work.
e.g.
For custom
usage:
(It is often more convenient to implement the
than using
This wayyou do not need
MenuItem上显示快捷键:
<MenuItemHeader="{x:Static Prop:Resources.File_AddBookItemHeader}" InputGestureText="Ctrl+N"Command="local:CustomCommands.DoStuff" Foreground="Black"/>
也可以不用再xaml中声明keyBinding,而用代码:
static classCustomCommands
{
public staticRoutedCommand DoStuff = new RoutedCommand();
staticCustomCommands()
{
DoStuff.InputGestures.Add(new KeyGesture(Key.N, ModifierKeys.Control));
}
}
参考:http://stackoverflow.com/questions/4682915/defining-menuitem-shortcuts
You need to use
KeyBindings(and
CommandBindingsif
you (re)use
RoutedCommandssuch as those found in the
ApplicationCommandsclass)
for that inthe controls where the shortcuts should work.
e.g.
<Window.CommandBindings>
<CommandBinding Command="New" Executed="CommandBinding_Executed" />
</Window.CommandBindings>
<Window.InputBindings>
<KeyBinding Key="N" Modifiers="Control" Command="New"/>
</Window.InputBindings>
For custom
RoutedCommands:
static class CustomCommands
{
public static RoutedCommand DoStuff = new RoutedCommand();
}
usage:
<Window
...
xmlns:local="clr-namespace:MyNamespace">
<Window.CommandBindings>
<CommandBinding Command="local:CustomCommands.DoStuff" Executed="DoStuff_Executed" />
</Window.CommandBindings>
<Window.InputBindings>
<KeyBinding Key="D" Modifiers="Control" Command="local:CustomCommands.DoStuff"/>
</Window.InputBindings>
...
</Window>
(It is often more convenient to implement the
ICommandinterface rather
than using
RoutedCommands. You canhave a constructor which takes delegates for
Executeand
CanExecuteto easily create commands which do different things, suchimplementations are often called
DelegateCommandor
RelayCommand.
This wayyou do not need
CommandBindings.)
MenuItem上显示快捷键:
<MenuItemHeader="{x:Static Prop:Resources.File_AddBookItemHeader}" InputGestureText="Ctrl+N"Command="local:CustomCommands.DoStuff" Foreground="Black"/>
也可以不用再xaml中声明keyBinding,而用代码:
static classCustomCommands
{
public staticRoutedCommand DoStuff = new RoutedCommand();
staticCustomCommands()
{
DoStuff.InputGestures.Add(new KeyGesture(Key.N, ModifierKeys.Control));
}
}
相关文章推荐
- centos7 rhel7 linux下怎么安装google chrome 设置谷歌浏览器桌面快捷方式
- Advanced Office Password Recovery快捷方式怎么设置
- C#入门学习-----菜单应用(添加剂快捷方式、设置菜单项是否可用、修改菜单字体、创建级联菜单、级联菜单的动态合并)
- 怎么设置桌面关机的快捷方式
- Windows mobile 平台 在platform.dat中创建快捷方式,链接到中文路径 字符\Windows\“开始”菜单\设置
- Android Studio 如何设置代码快捷方式
- 显示桌面快捷方式为什么不见了怎么办怎么找回来?
- 关于InstallShield Express-快捷方式的工作目录的设置
- WPF中设置快捷键(ctrl+S等)
- Myeclipse 的基本设置以及快捷方式
- 让开始菜单中的文件夹快捷方式以文件有下级菜单方式显现
- 显示桌面的快捷方式被删掉了怎么办
- 右键菜单添加包含ICON图片的快捷打开方式
- Android桌面快捷方式的设置(二)
- Linux Mint创建应用程序菜单及桌面快捷方式
- ubuntu下右键菜单添加新建word、excel文档等快捷方式.
- 在jsp页面page指令中pageEncoding怎么设置默认编码方式为utf-8?
- 如何设置Hyper-V的虚拟机快捷方式
- win7桌面图标删不掉怎么办 桌面快捷方式或桌面文件删除教程
- windows8系统怎么创建无线连接及设置方式具体图解