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

查看:234
本文介绍了为什么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我来自这里

  • DelegateCommands我来自此处

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

以某种方式处理ComboBox中的ItemSelected事件,并获得技巧和解决方法的建议(使用XAML触发器或将其他元素绑定到所选项目) ,等等)。好吧,我可以走这条路,但它似乎是重塑的轮子。这将是很好,只有一个 ItemSelected命令,我可以在我的ViewModel 中处理。

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的人都使用WPF基本上构建和集合他们自己的工具集合,可以使用事件和命令做最简单的管道任务,只需要在代码后面加上一行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月在约翰·高斯曼的博客 a>。

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

从那时起,我想说再花两三年的时间,WPF / MVVM才真正起飞,被社区接受,那时候太晚了改进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天全站免登陆