Which MVVM framework is the best framework for WPF

2019-01-07 05:59发布

问题:

I am a beginner with WPF. Before developing mid and large size project best on WPF, I need to work with open source/free MVVM framework for WPF, so please tell me which MVVM framwork would be the right choice for WPF apps with help of which I can develop very attractive UI for enterprise apps, and which comes with good tutorial and plenty sample code for becoming acquainted with the flow of the framework. Please discuss in detail. Thanks.

回答1:

This question is really difficult to answer objectively, because what's best for you depends so much on your requirements and preferences. I've used two frameworks myself, so those are the ones I can talk about.

One of the most popular MVVM frameworks is MVVM Light Toolkit, which is a versatile framework which allows you to construct applications the way you want. It provides help getting around some of the main pain points in building MVVM applications, but it still requires you to write a lot of the boilerplate code yourself. This might be good for a new WPF developer, because it doesn't hide away so much of the WPF infrastructure.

My personal favorite is Caliburn.Micro, which is an opinionated MVVM framework for WPF, Silverlight and Windows Phone 7. It uses a convention-over-configuration approach, which saves you from writing a lot of the boring, tedious plumbing code. This also means that it requires you to agree with the framework's opinion - if you don't follow the conventions it prescribes you'll be fighting an uphill battle to make everything work.

Caliburn.Micro also has the quality of just working, and if you don't really understand what's going on under the hood, things can seem a little magical. This is great, as long as things are working. But when they don't, or you need to do something the framework isn't designed to do, you'll need a pretty solid understanding of WPF to find your bearings.

You need to evaluate the features of different frameworks and toolkits and decide for yourself.



回答2:

There are many popular open source MVVM frameworks.

Probably the three most popular would be MVVM Light, Caliburn, or Prism (which, as of v4, supports and provides examples of MVVM). All three have strengths and weaknesses, and all are good.

Prism does have the advantage of being a "Microsoft" (sponsored) product, as it's put out by the Microsoft Patterns and Practices group. This tends to help adoption in many larger enterprises. That being said, it's also far larger and more complicated than the other popular options, especially as its goal isn't just to be an "MVVM Framework", but rather a general purpose library for composite application development.


I am beginner for WPF.

I also thought I'd mention - before you pick a framework, I would spend some time really trying to learn and understand MVVM. I wrote a series to help transition to WPF with MVVM from Windows Forms which may be of value.

Often, its difficult to pick a framework until you understand what it's really accomplishing. Most of MVVM can be done, very easily, with no framework whatsoever. The "frameworks" add utilities that make certain pain points of MVVM development easier to handle - for example, MVVM Light has a great Messenger class that helps with communication between ViewModels, which can be tricky at times. Caliburn has some great tools to help with designability, etc. However, until you understand the basics, choosing a toolkit may actually make your life more complicated, not simpler.



回答3:

Maybe in order to get taste of MVVM you do not need to use any libraries at all? It's easy to implement basic stuff (DelegateCommand and class to raise property notifications - is everything you need), but this will help you understanding MVVM without introducing any library. Probably you will meet some obstacles during this implementation and you will have to solve it on your own, without any third-party libraries. I believe this may help you elaborate more clear vision on MVVM pattern (of course if you will have a good guidance) but without introducing specifics provided by libraries.

Maybe I'm a wheel inventor a little bit, but I still do not use any MVVM libraries at all. I just do not see anything that great they can provide in order to introduce yet another library into project. It usually doesn't take a lot to implement basic stuff you need for MVVM but at the end you receive highly flexible code (because all code is yours).



标签: wpf mvvm