我有一个程序,我需要访问从键盘输入到视图模型中的字符。我可以使用 KeyUp 方法在后面的代码中轻松获取 KeyEventArgs,但是如何在 ViewModel 中访问它?请帮忙。
问问题
339 次
1 回答
0
You need the following to pass keyEventArgs to viewmodel
1. Interaction triggers in xaml because native input binding don't support keyeventargs
<textblock>
<i:interactiontriggers>
<i:action eventname ="keyup">
<multibinding command={binding somecommand, converter={staticresource eventconverter}}">
<binding ...>
<binding...>
</multibing>
</i:action>
</i:interactiontriggers>
</textblock>
2 Create a custom command (example, relay command) where you can initialize the command like below in viewmodel
var cmd = SomeCommand;
Customcommand c = new RelayCommand<KeyEventArgs>(cmd.Execute, cmd.CanExecute);
3. In the command action, you can access the mouseeventargs or keyeventargs.
If you look up more, you'll get an idea.
于 2014-12-02T04:11:34.487 回答