To MVVM or not to MVVM that is the question [closed] To MVVM or not to MVVM that is the question [closed] wpf wpf

To MVVM or not to MVVM that is the question [closed]


My take is to use MVVM, but not religiously.

I mean, use a model to your views, but also use some code behind when needed (drag&drop, double-click). Find a balance that helps your development, without driving you nuts.


MVVM lends itself very well to WPF. Can you do drag-drop with WPF and MVVM? Sure you can. Try searching for "WPF Drag Drop Behavior"


There are two really good reasons to go with MVVM:

  1. It helps you produce business logicand data access code that is moreeasily unit tested
  2. With very little extra effort, allof your UX should be easy to modifyin Blend

As several posters have metioned, any eventing related to the UX can be handled in code-behind, but you should be exposing and accessing (read and write) data through your View Models for easy binding in your Views.

As for the extra effort I referred to in #2, you could easily add a static property to your App object to determine if the application is running versus a View being opened in Blend. If the View is open in Blend, leverage mock data instead of making data access calls. Here's some sample code that works for checking if Blend has a View open:

if (Application.Current == null || Application.Current.GetType() == typeof(Application)){    isInDesignMode = true;}else{    isInDesignMode = false;}

Hope this helps.