我应该如何处理多个事件每个控制w /命令模式使用MVVM在Silverlight中? [英] How should I handle multiple events per control w/command pattern using MVVM in Silverlight?

查看:235
本文介绍了我应该如何处理多个事件每个控制w /命令模式使用MVVM在Silverlight中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人使用SLExtensions命令模式( http://www.codeplex.com/SLExtensions ) )用于将命令与Silverlight控制事件相关联?从我看到的,你只能为每个控件一个事件附加一个命令。例如,您只能为按钮添加点击事件,为文本框添加按键事件等。

Is anyone using the SLExtensions command pattern (http://www.codeplex.com/SLExtensions) for associating commands to Silverlight control events? From what I've seen, you can only attach a command for one event per control. For example, you can only add a click event for a button, a keydown event for a textbox, etc.

如果我想为每个控件添加多个事件会怎么样?例如,如果我想为一个按钮的Click和Drop事件添加命令。开箱即用似乎没有办法处理这个与SLExtensions代码。

What if I wanted to add multiple events per control? For example, what if I wanted to add commands for both Click and Drop events for a button. Out of the box there does not seem to be a way to handle this with the SLExtensions code.

BTW,这是在一个Model-View-ViewModel(MVVM)上下文。

BTW, this is in a Model-View-ViewModel (MVVM) context.

推荐答案

我不熟悉SLExtensions,但在WPF中,每个控件有一个命令的限制,通过控制实现。如果你想要一个命令执行另一个事件,你必须自己连线。然而,有一个解决方案,不需要你做这个接线在代码背后...附加行为。事实上,Caliburn( http://www.codeplex.com/caliburn )只是通过它的行动的概念。我没有看过Caliburn很长时间,不知道它是否与Silverlight兼容,但你一定可以看看Action如何编写在那里,并实现自己的。

I'm not familiar with SLExtensions but in WPF you have the same limit of one command per control, which is associated by the control implementation. If you want a command to execute for another event, you have to wire that yourself. However, there is a solution that doesn't require you to do this wiring in the code behind... attached behaviors. In fact, Caliburn (http://www.codeplex.com/caliburn) does just this with its "Action" concepts. I've not looked at Caliburn in a long time, and have no idea if it's Silverlight compatible, but you can certainly look into how the Actions are codified there and implement your own.

这篇关于我应该如何处理多个事件每个控制w /命令模式使用MVVM在Silverlight中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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