文本框MVVM中的按键 [英] Key press inside of textbox MVVM

查看:187
本文介绍了文本框MVVM中的按键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始使用MVVM,并且在解决如何将文本框中的按键压缩到视图模型中的ICommand之前,我有问题。我知道我可以在代码隐藏中做到这一点,但是尽量避免这种情况。

I am just getting started with MVVM and im having problems figuring out how I can bind a key press inside a textbox to an ICommand inside the view model. I know I can do it in the code-behind but im trying to avoid that as much as possible.

更新:迄今为止的解决方案都很好,如果你有混合sdk或你没有问题的交互dll这是我拥有的。有没有其他更通用的解决方案,而不是使用混合sdk?

Update: The solutions so far are all well and good if you have the blend sdk or your not having problems with the interaction dll which is what i'm having. Is there any other more generic solutions than having to use the blend sdk?

推荐答案

优秀的WPF框架 Caliburn 精美地解决了这个问题。

The excellent WPF framework Caliburn solves this problem beautifully.

        <TextBox cm:Message.Attach="[Gesture Key: Enter] = [Action Search]" />

语法[Action Search]绑定到视图模型中的一个方法。完全不需要ICommands。

The syntax [Action Search] binds to a method in the view model. No need for ICommands at all.

这篇关于文本框MVVM中的按键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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