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

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

问题描述

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

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.

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"?

解决方案

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

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.

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

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.

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

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