views:

561

answers:

1

Users love animations. See the iphone for a good example :) Everything a user does in the iphone kicks off an animation.

Enter MVVM and Commanding (I'm thinking about Silverlight 2 specifically). A user action triggers an event via Commanding, and we're sitting in the ViewModel thinking about how to trigger a nice animation for the user...

There are some possibilities, but I don't find any of them particularly tasteful.

  • A bit of MVP. Have the View implement an interface and then have the VM call a method on the view to start an animation.
  • In Silverlight 3 Actions/Behaviors might be a kind of answer, but I'm trying to figure out the best approach for SL 2.
  • Do hokey animations from the VM where you update (via a timer) binding properties to make things happen... Pretty awkward.

Has anyone had good success with an approach?

+1  A: 

Typically I use events to fire the animations from the viewmodel in Silverlight 2

zachary
Any good examples of this? I imagine the View expresses an event (maybe through a MVP sorta interface), and the VM fires the event at the appropriate time. Have you found a good way to wire up the events? Why not call a straight-up method on the View's interface (assuming MVP)? lol. I've got a lot of questions :)
Erik Mork
The viewmodel was actually the one firing the event. The idea being that the viewmodel should not know anything about the view. Then the view would handle the event. I'm sure an interface would work too. I have seen that a lot with Model View Presenter. I wasn't really that happy with either method. Hopefully someone will come along with something better :-)This is the best article I ever read on events (including the following comments)http://geekswithblogs.net/HouseOfBilz/archive/2009/02/15/re-thinking-c-events.aspx
zachary
Thanks. Ya, I think SL 3 (Behaviors) is going to open some avenues in the future. The problem is a toughy on SL 2.
Erik Mork
It would be more helpful if you could actually show how to do it...
Padu Merloti