Currently, I'm implementing MVVM pattern for a WPF application but not 100% no code behind, sometimes I put some business logic code into GUI and so what are potential problems for this? Thanks

1 Answer 1


The whole point of MVVM is to abstract as much logic as possible away from the View, the surface that the user sees. If you're using CodeBehind to implement business logic, you're probably not practicing MVVM.

This has several benefits:

  1. It makes the code more testable. UI is difficult to test, especially UI that has CodeBehind.
  2. If the business logic is somewhere else besides the UI, you can swap out the UI for another UI (such as a mobile device or web page), and the business logic will still work.

Of course, if this is a very small application and you never intend to talk to a database on a server (a rarity these days), you may not need all this ceremony; CodeBehind might be perfectly adequate.

  • 1
    CodeBehind is ok until it contains buisness logic. View's internal logic can be in the CodeBehind without breaking MVVM pattern
    – Fabio
    Oct 23, 2015 at 12:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.