使用键盘快捷键触发 Silverlight Prism 命令

Triggering Silverlight Prism command with a keyboard shortcut(使用键盘快捷键触发 Silverlight Prism 命令)
本文介绍了使用键盘快捷键触发 Silverlight Prism 命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道是否可以使用快捷方式触发棱镜命令吗?我的意思是我希望能够以声明方式定义命令与键盘快捷键的绑定,例如 但我认为它没有答案我的.

解决方案

我已经创建了这样的手势触发器.我想和你们分享.基本上,它是 System.Windows.Interactivity 触发器,可以解析表示为字符串的手势.用法和在 ClientUI 中一样简单:

<UserControl><i:Interaction.Triggers><行为:KeystrokeCommandTrigger Command="{Binding SaveChangesCommand}" Gesture="Ctrl+Shift+S"/><行为:KeystrokeCommandTrigger Command="{Binding RejectChangesCommand}" Gesture="Ctrl+Shift+R"/><行为:KeystrokeCommandTrigger Command="{Binding NewItemCommand}" Gesture="Ins"/><行为:KeystrokeCommandTrigger Command="{Binding DeleteSelectedItemCommand}" Gesture="Del"/><行为:KeystrokeCommandTrigger Command="{Binding UploadSomethingCommand}" Gesture="Ctrl+Shift+U"/></i:Interaction.Triggers></用户控制>

代码在pastie上.

Does anybody know whether one can trigger prism command with a shortcut? What I mean is I want to be able to define binding of a command to keyboard shortcut in declarative manner, like ClientUI does:

Are there any opensource libraries for that purpose? Or maybe code samples?

I found this question but I don't think that it answers mine.

解决方案

I've created such gesture trigger. And I'd like to share it with you guys. Basically, it is System.Windows.Interactivity trigger which can parse gestures represented as strings. Usage is as simple as in ClientUI:

<UserControl>
    <i:Interaction.Triggers>
        <behaviors:KeystrokeCommandTrigger Command="{Binding SaveChangesCommand}" Gesture="Ctrl+Shift+S" />
        <behaviors:KeystrokeCommandTrigger Command="{Binding RejectChangesCommand}" Gesture="Ctrl+Shift+R" />
        <behaviors:KeystrokeCommandTrigger Command="{Binding NewItemCommand}" Gesture="Ins" />
        <behaviors:KeystrokeCommandTrigger Command="{Binding DeleteSelectedItemCommand}" Gesture="Del" />
        <behaviors:KeystrokeCommandTrigger Command="{Binding UploadSomethingCommand}" Gesture="Ctrl+Shift+U" />
    </i:Interaction.Triggers>
</UserControl>

The code is on pastie.

这篇关于使用键盘快捷键触发 Silverlight Prism 命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)