2

I have a WPF application that should be compact, with minimal possible memory footprint. The GUI is simple from the point of view of flow, few pages and grids, but quite rich from the point of view of graphics, animations etc.

I have experience writing applications with Prism and I like it very much. But it looks too heavy for simple tasks. It is not a LOB application, but I still need testability, GUI/flow/business separation etc.

Should I use MVVM anyway?

I am not sure if the overhead of using the MVVM design pattern is something I should worry about or not when trying to minimize the memory usage of my application.

Rachel
  • 130,264
  • 66
  • 304
  • 490
Dmitry Karpezo
  • 1,054
  • 11
  • 26
  • 2
    [MvvmLight toolkit](http://mvvmlight.codeplex.com/) is very very lightweight. In fact, that's why I use this framework. It does MVVM and only MVVM. – Steve B Jul 19 '12 at 13:49
  • 1
    Also, have a look at [Caliburn Micro](http://caliburnmicro.codeplex.com/). – Eddie Flores Jul 19 '12 at 14:02
  • I made a few edits to remove the extra questions that got this closed, and have voted to reopen this. – Rachel Jul 19 '12 at 18:12

3 Answers3

6

Yes, use MVVM if you're working with WPF

WPF is designed so you have a UI layer and a data layer, and this suits the MVVM design pattern perfectly. I find it makes the coding and maintenance much faster and easier.

You don't have to use a full fledged MVVM framework, or even any MVVM framework at all. You can pick and choose the parts you're interested in using (a base object that inherits INotifyPropertyChanged, a RelayCommand or DelegateCommand, the messaging system, etc) and drop all the rest. Or you can build your own.

The amount of overhead is minimal and definitely not worth avoiding the pattern for, however some MVVM frameworks do include unneeded features and can cause some overhead, so be sure you only pick the pieces you want out of them.

The point is, use the MVVM design pattern if you're working with WPF. It will make your life, and any future developers that work on the project lives, much easier :)

Rachel
  • 130,264
  • 66
  • 304
  • 490
4

I really would recommend using MVVM.

We used the pattern in a huge project and it worked well, with the following recommendations:

  • we use the very useful, and as the name says, light, MVVM Light Toolkit lib
  • we do not use the ViewModelLocator thing. Too hard to make it work when you dynamically instantiate Views. The good old this.Datacontext = new TheViewModel(); in the code-behind is fine
  • we do not use the Messenger thing. Too complicated for very little benefits. A good old event fired from the view model is way more simple IMO.
  • we do not use the EventToCommand thing, which complicates the XAML for nothing in lots of cases.
  • we do write code behind when the code is purely related to the view. For mouse gesture features (drag & drop...) or other specific UI things, code-behind is fine for control events handling.
ken2k
  • 48,145
  • 10
  • 116
  • 176
2

First of all: Yes, MVVM is a recommend way of how to architect an C# / WPF application

Second: You can use MVVM with not framework at all, then it is as lightweight as you build it.

Look here for an overview of possible MVVM frameworks: SO in depth discussion of different MVVM frameworks

Community
  • 1
  • 1
Mare Infinitus
  • 8,024
  • 8
  • 64
  • 113