Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Learning WPF and MVVM

Tags:

c#

.net

mvvm

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.

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.

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

like image 448
Kane Avatar asked Jan 10 '10 08:01

Kane


People also ask

Is MVVM worth learning?

In short: MVVM is not pointless, it's great. NET 4.0 WPF's control library is trash. Here is the simple proof of concept ViewModel which you can't data bind in pure MVVM manner using WPF.

Do you need MVVM for WPF?

WPF assumes MVVM for most things. e.g. using a the wpf tree control without MVVM will have you tearing your hair out within a day.. MVVM just makes things simpler and testable. This could answer some of the questions: wintellect.com/CS/blogs/jlikness/archive/2010/04/14/….

What is MVVM in WPF C#?

MVVM (Model-View-ViewModel) MVVM is a way of creating client applications that leverages core features of the WPF platform, allows for simple unit testing of application functionality, and helps developers and designers work together with less technical difficulties.


2 Answers

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.

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.

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

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

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.

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

like image 87
Steve Psaltis Avatar answered Oct 21 '22 08:10

Steve Psaltis


I have faced a similar situation, and the route I decided to go was:

  • Use ViewModels for my views, but avoid some MVVM pureness, like Attached Behaviors (which I find dumb and clunky)
  • Use Magellan MVC framework, which fit best my mental model about how an applications should behave.
like image 37
Eduardo Molteni Avatar answered Oct 21 '22 08:10

Eduardo Molteni