基于WAF框架:WPF Application Framework (WAF)

View层XAML中设置热键。

    <Window.InputBindings>
<!--<KeyBinding Command="{Binding SaveCommand}" Key="S" Modifiers="Control"/>-->
<KeyBinding Command="{Binding AboutCommand}" Key="F1"/>
</Window.InputBindings>

ViewModel中定义该AboutCommand命令。


private ICommand aboutCommand;
public ICommand AboutCommand
{
get { return aboutCommand; }
set { SetProperty(ref aboutCommand, value); }
}

控制层写AboutCommand命令的实现。

namespace WafApplication1.Applications.Controllers
{
[Export]
internal class ApplicationController
{
private readonly ShellViewModel shellViewModel;
private readonly DelegateCommand aboutCommand; [ImportingConstructor]
public ApplicationController(ShellViewModel shellViewModel)
{
this.shellViewModel = shellViewModel;
this.aboutCommand = new DelegateCommand(AboutCommand);
} private void AboutCommand()
{
MessageBox.Show("F1 Command!");
} public void Initialize()
{
shellViewModel.AboutCommand = this.aboutCommand;
} public void Run()
{
shellViewModel.Show();
} public void Shutdown()
{
}
}
}

运行该项目,按F1即可看到弹出弹窗。


新的问题

给该Window窗体注册的快捷键,必须要在该窗体获得焦点时快捷键才有效。如果该窗体内有别的控件(如ListBox)获取了焦点,再点击该快捷键将不起效果。这时候,可考虑同样给该ListBox控件添加相同的快捷键命令。

<!-- 快捷键 -->
<ListBox.InputBindings>
<KeyBinding Command="{Binding ShortcutScaleCommand}" Key="F1"/>
</ListBox.InputBindings>

最新文章

  1. vue+node开发手机端h5页面开发遇到的坑
  2. SQLServer根据日期查询星期
  3. Centos 6.5 下php5.6.2 的编译安装
  4. .NET/android/java/iOS AES通用加密解密
  5. spring常见异常
  6. 【C语言】16-预处理指令2-条件编译
  7. ACM常用算法及练习(1)
  8. UIKit框架之UIlabel
  9. QT5-控件-QDateEdit 和 日期类QDate
  10. java基础之基础语法详录(一)
  11. 微信小程序xml解析
  12. uuid.go
  13. windows设置照片查看器为默认的照片查看软件
  14. Python并发复习4- concurrent.futures模块(线程池和进程池)
  15. sql中join与left-join图解区别
  16. Scrum Meeting 7
  17. 项目梳理5——修改已生成.nuspec文件
  18. 如何让chrome浏览器自动翻译
  19. ZOJ 4010 Neighboring Characters(ZOJ Monthly, March 2018 Problem G,字符串匹配)
  20. 总结day7 ---- 函数的内容 ,初识,返回值,进阶(一)

热门文章

  1. 面试题 Comparable、Comparator 比较
  2. Oracle自治事务实际用例
  3. 使用springboot遇到的的异常
  4. 使用winsound模块播放声音
  5. 【LeetCode】31. Next Permutation (2 solutions)
  6. eclipse svn登陆用户保存信息删除
  7. 【php】基础学习3
  8. python练习笔记——计算1/1-1/3+1/5-1/7……的和
  9. Kruskal算法 - C语言详解
  10. eclipse逆向生成实体类注解方式或者xml方式