为什么MVVM中的事件和命令不受WPF / Visual Studio的支持? [英] Why are events and commands in MVVM so unsupported by WPF / Visual Studio?

查看:225
本文介绍了为什么MVVM中的事件和命令不受WPF / Visual Studio的支持?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当创建具有MVVM模式的WPF应用程序时,似乎我必须自己收集必要的工具,甚至开始最基本的事件处理,例如。

When creating an WPF application with the MVVM pattern, it seems I have to gather the necessary tools myself to even begin the most rudimentary event handling, e.g.

  • AttachedBehaviors I get from here
  • DelegateCommands I get from here

现在我正在寻找一些方式来处理ComboBox 中的ItemSelected事件,并获得技巧和解决方法的建议(使用XAML触发器或将其他元素绑定到所选项目等) )。好的,我可以沿着这条路走下去,但似乎正在重塑车轮。只需要在我的ViewModel 中处理一个 ItemSelected命令就可以了。

Now I'm looking for some way to handle the ItemSelected event in a ComboBox and am getting suggestions of tricks and workarounds to do this (using a XAML trigger or have other elements bound to the selected item, etc.). Ok, I can go down this road, but it seems to be reinventing the wheel. It would be nice to just have an ItemSelected command that I can handle in my ViewModel.

我缺少一些标准工具,或者每个人都使用WPF来做MVVM,基本上是建立和组合自己的工具集合,可以使用事件和命令来做最简单的管道任务,只需要使用Click =eventHandler代码中的几行即可。

Am I missing some set of standard tools or is everyone doing MVVM with WPF basically building and putting together their own collection of tools just so they can do the simplest plumbing tasks with events and commands, things that take only a couple lines in code-behind with a Click="eventHandler"?

推荐答案

根据Josh Smith关于MVVM的文章,它于2005年10月在约翰·戈斯曼的博客

According to Josh Smith's article about MVVM, it was unveiled to the world in October 2005 on John Gossman's blog.

从那时起,我会说WPF / MVVM需要2到3年才能真正起飞并被社区接受,那么现在为时已晚改造WPF来支持MVVM的问题。另外我会说WPF创建了MVVM,所以似乎有一个WPF改变来支持MVVM。

From then I'd say it took another 2-3 years for WPF/MVVM to really take off and be accepted by the community, by then it was too late to retrofit WPF to support the issues with MVVM. Also I'd say that WPF created MVVM, so it seems backwards to have WPF change to support MVVM.

最后,不是所有做WPF的人都使用MVVM,所以API需要支持事件的标准使用等

Finally, not everyone doing WPF uses MVVM, so the API needs to support the standard usage of events etc

所以,为了回答你的问题,是的,大家现在都把自己的工具集合在一起,因为官方支持只提供DelegateCommands框架在此时。

So, to answer your question, yes everyone is currently putting their own set of tools together as the "official" support only provides the DelegateCommands framework at this time.

这篇关于为什么MVVM中的事件和命令不受WPF / Visual Studio的支持?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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