学习WPF和MVVM [英] Learning WPF and MVVM

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

问题描述

我最近加入了一个新的开发项目,该项目使用WPF和MVVM构建胖客户端应用程序.我已经开发了从1.1到3.5的各种.NET框架中的应用程序,以及所有主要技术.WebForms,MVC和WinForms.在我所有的项目中,我都喜欢它的每一分钟,但是在这个项目中,我感到自己很挣扎,因此不那么喜欢它.当.NET 3.5在2008年问世时,我真的很喜欢学习新的语言功能(LINQ,MVC,Lambda表达式等)并涉足WPF,所以请不要以为我反对学习新的东西.

I have recently joined a new developing project building a thick client application using WPF and MVVM. I have developed applications in various .NET frameworks from 1.1 through to 3.5 and all major technologies; WebForms, MVC and WinForms. On all of my projects I have enjoyed every minute of it but on this project I feel that I am struggling and as such not enjoying it as much. When .NET 3.5 came out in 2008 I really enjoyed learning the new language features (LINQ, MVC, Lambda Expressions, etc) and dabbled in WPF so please don't assume I'm against learning something new.

但是该项目的学习曲线似乎非常陡峭,我觉得在WPF +应用程序之上学习MVVM有点令人生畏.尽管我只参加了短时间(2周)的项目,但我确实很喜欢WPF,但是对MVVM模式不满意.我不喜欢MVVM模式,可能是因为我不太了解它,并且我觉得必须写很多非最佳实践"代码才能完成WinForms时代相对简单的事情.

But the learning curve on this project seems really steep and I feel that learning MVVM on top of WPF + the application is a little daunting. Although I have only been on the project for a short time (2 weeks) I really like WPF but have taken a disliking to the MVVM pattern. My disliking to the MVVM pattern may because I don’t really understand it and I feel that I have to write a lot of "non best practice" code in order to do what was relatively simple in my WinForms days.

所以我的问题是,还有其他人遇到过类似的情况吗?您是坚持使用MVVM还是朝着另一个体系结构方向发展?

So my question is has anyone else faced a similar situation and did you stick with MVVM or go in another architectural direction?

推荐答案

自Beta版本以来,我一直在使用WPF,并且我永远不会再使用winforms.对我而言,MVVM是一种哲学,要忠实地实施它需要大量的工作和纪律.它鼓励UI与交互逻辑之间完全去耦,这意味着不存在任何代码,这意味着可测试的交互逻辑,这对于winforms来说是非常困难的.

I have been working with WPF since the beta versions and I would never go back to winforms. To me MVVM is a philosophy and it takes a lot of work and discipline to implement it faithfully. It encourages complete decoupling between UI and interaction logic which means no code behind whatsoever which means testable interaction logic which is very difficult to do with winforms.

与gius相比,我建议您坚持使用普通的WPF和MVVM,尤其是如果您刚开始使用WPF.MVVM和WPF有很多要掌握的内容,否则只会减慢您的进度.但那只是我的个人意见.我总是更喜欢分层学习,而不是试图一次学习所有东西,那样您可以控制一切,并且对应用程序的工作方式有更多的了解.

In contrast to gius I would recommend you stick with plain WPF and MVVM especially if you are just starting out with WPF. There is a lot to grasp with MVVM and WPF, adding to that will just slow down your progress. But that's just my opinion. I always prefer to layer my learning rather than try to learn everything at once that way you are in control and you have more knowledge about how your application works.

如果您尚未这样做,我强烈建议您阅读MVVM上的MS文章:

If you have not already done so I strongly recommend you read the MS article on MVVM :

http://msdn.microsoft.com/en-us/magazine/dd419663.aspx

这太棒了,对于写任何WPF代码的团队成员来说,这是必读的内容.

Its fantastic and it is compulsory reading for my team members who write any WPF code.

我不确定您和您的团队的工作方式,但是您需要自己问一下MVVM是否适合您.如果单元测试/测试驱动和分离的UI已经在执行中或对您很重要,那么MVVM绝对是一个不错的选择.如果您的团队对在后面编写代码感到满意,并且您不知道为什么要打扰去耦,那么就不要打扰MVVM,因为这样会降低速度.就我个人而言,后者绝对不是我的选择.

I am not sure how you and your team work but you need to ask yourselves whether or not MVVM is for you. If unit testing / test driven and decoupled UI is something you are already doing or is important to you then MVVM is definitely a good path to take. If your team is happy with writing code behind and you don't see why you should bother decoupling then don't bother with MVVM as you will find that it will slow you down. Personally the latter is never an option for me.

如果对WPF或MVVM有任何特定问题,请随时与我联系.

Please feel free to contact me if you have any specific questions about WPF or MVVM.

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

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