问题描述
我的窗口只有一个列表视图.这便于用户增量搜索数据库.由于设计没有文本框,因此我必须全局处理键.我认为可以通过绑定来实现.但是我该如何处理所有键并将其关联到单个命令.
My window has just a listview. This facilitates the users to incremental search the db. Since the design does not have a textbox, i've to globally handle the keys. I think it could be achieved by keybinding. But how can i handle all the keys and associate it to a single command.
还建议我其他方法.
P.S .:我想要xaml
P.S.: I want this in xaml
推荐答案
我将使用EventToCommand将KeyDown事件绑定到ViewModel上的命令.您可以将PassEventArgsToCommand设置为true,然后使用RelayCommand来找出按下的键.
I would use an EventToCommand binding the KeyDown event to a command on the ViewModel. You can set PassEventArgsToCommand to true, and use a RelayCommand to find out what key as pressed.
MVVM Light Toolkit中提供了所有这些对象
All these objects are available in the MVVM Light Toolkit
http://www.galasoft.ch/mvvm/getstarted
干杯,洛朗(Laurent)
Cheers,Laurent
这篇关于多个键绑定到单个命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!