views:

93

answers:

1

In the View-Model-ViewModel, actions are essentially executed by the viewmodel that is bound to the view. However, where would the "presentation logic" go since the code behind isn't used and the viewmodel has no reference or knowledge of the control that invoked it?

For example, what if I wanted to animate another control when a button is clicked. Would this still go in the code behind?

+1  A: 

To expand on Justin Niessner's comment, I'd be using a trigger to achieve this animation as it's all UI bound.

Think about this:

  • Where would you put code so that when someone mouses over a button it becomes hilighted?
  • What about code for "depressing" that button when it is clicked?

These and your question are all variations on a theme, so I'd say do it in the GUI.

However, there's one exception to this rule. If the "animation" is a processing animation, then it might be worth tying it to the ViewModel so the ViewModel can control how long the animation runs while it's processing something. Otherwise do it in the GUI.

EDIT: Based on your comment. Ok so the animation should run off a property in the ViewModel, not the button click event. The Click should start the processing in the ViewModel through a command, and the execute code for that command should set a processing flag property on the ViewModel. Then the View can bind to that processing flag and display a progress bar or whatever when that flag is set.

Cameron MacFarland
So lets say you needed to do it in the viewmodel because the animation is based on something that's quantifiable like "number of X" (like animating a chart). Would you still write code in your code behind to accomplish this?
Korbin