使用键盘快捷键触发 Silverlight Prism 命令 [英] Triggering Silverlight Prism command with a keyboard shortcut

查看:36
本文介绍了使用键盘快捷键触发 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 命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆