1

I'm probably just confused about how MVVM works normally.

I have a property (zoomlevel) that I don't really think is a property of the data itself, so I don't feel like it goes in the viewmodel. I feel like that it is really a property of the view, so I'm hesitant to place the command handling this into the viewmodel.

Is it ok to have a relaycommand just attached to the control in the view that needs to process this command?

I guess this is really a question of whether MVVM requires no code behind at all because I feel like it makes more sense to place the actual code that performs the command inside the controls as opposed to placing the code in the viewmodel and then updating the controls based on some properties of the viewmodel

James Joshua Street
  • 3,259
  • 10
  • 42
  • 80
  • This has already been addressed in another question: http://stackoverflow.com/questions/6421372/why-to-avoid-the-codebehind-in-wpf-mvvm-pattern – AnotherDeveloperNamedGreg Sep 13 '13 at 23:01
  • 1
    ViewModels are meant to model the View, so although ZoomLevel might not be a data property that goes on your Models, it might be a view-specific business property that belongs on your ViewModel. Of course, if it really is a view-specific property that has no relation to your application logic, feel free to place it in the code behind the View :) – Rachel Sep 13 '13 at 23:13

1 Answers1

4

MVVM is a architectural design pattern, that basically describes how to separate UI from logic.

It does so by promoting that you put logic in your VM. It does not say anywhere, that I'm aware of, that you shouldn't use a code-behind file nor does it say that you should never put code in it.

I use MVVM but still have a code-behind file. For instance, it is an ideal place to put UI specific code, which could be somewhat difficult to do in the VM.

makim
  • 3,154
  • 4
  • 30
  • 49