在MVVM Silverlight的热键命令? [英] Hotkey commands for Silverlight in MVVM?
问题描述
我试图开火基于Silverlight中按键的命令。据我所知,你不能在Silverlight中使用ACCESSKEY或AcceleratorKey。此外,它看起来可能会有所帮助附加属性InputBindings也不行。
I'm trying to fire commands based on keystrokes in Silverlight. As I understand you cannot use AccessKey or AcceleratorKey in Silverlight. Also it looks like the might be helpful attached property InputBindings does not work either.
我开始寻找在其他地方。它看起来像棱镜是得到在Silverlight的工作命令的方式,让我检查了这一点。不过,他们只有一个点击处理程序,它甚至不是获取设置键命令一个有益的起点。
I started looking in other places. It looked like Prism was the way to get commands working in Silverlight, so I checked that out. However they only have a Click handler, which isn't even a useful starting point for getting key commands set up.
我只思念棱镜的某些部分?还是有处理与热键Silverlight的MVVM一个很好的标准方式?
Am I just missing some part of Prism? Or is there a good standard way of handling hotkeys with MVVM Silverlight?
推荐答案
这听起来像你正在寻找一个无码处理在keyUp /的KeyPress / KeyDown事件MVVMish方式
It sounds like you're looking for a "codeless" MVVMish way of handling the KeyUp/KeyPress/KeyDown event.
选项#1:棱镜
。您'已经提到它只是船舶与点击命令。但是,您可以添加自己的连接的DPS enable命令对任何事件,你想(像的KeyUp /的KeyDown /按键)。
Option #1: Prism.
You've mentioned it only ships with the Click command. However, you can add your own attached DPs to enable commands for whatever event you'd like (like KeyUp/KeyDown/KeyPress).
如果您正在寻找在该科里的样品具有很好的一个ToggleButton.Checked /未选中的事件。
的http://www.85turns.com/2009/06/24/togglebutton-command-for-prism /
If you're looking for a sample on that Corey has a good one for ToggleButton.Checked/Unchecked events.
http://www.85turns.com/2009/06/24/togglebutton-command-for-prism/
<ToggleButton x:Name="ToggleButton1"
customCommands:Checked.Command="{Binding CheckedCommand}"
customCommands:UnChecked.Command="{Binding UnCheckedCommand}"
Margin="8,8,0,8" Content="Check me"
/>
此外,埃里克·莫克拥有出色的视频,让你的命令,以及如何创建一个很好的概述自定义命令连接DP。
http://development-guides.silverbaylabs.org/Video/Prism-Commands
方法2:混合触发
中的Expression Blend SDK附带触发器认识和行为上,以现场是什么你正在尝试做
混合范例 CodePlex项目随你可以使用的EventTrigger:
Option #2: Blend Triggers
The Expression Blend SDK ships with Triggers and Behaviours that are spot on to what you're try to do.
Blend Examples codeplex project ships with a EventTrigger you could use:
<i:EventTrigger EventName="Click">
<si:InvokeDataCommand Command="{Binding ShoppingCart.CheckOutCommand}"/>
</i:EventTrigger>
或者,你可以创建自己的自定义触发的击键事件和在那里做任何你希望保存。这里有一个例子:
的http:// azurecoding.net/blogs/brownie/archive/2009/04/06/blend-behaviors-ftw.aspx
Or, you could create your own custom Trigger for Key stroke events and do there whatever you'd like. Here's a sample:
http://azurecoding.net/blogs/brownie/archive/2009/04/06/blend-behaviors-ftw.aspx
这篇关于在MVVM Silverlight的热键命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!