开发者

Should animation cues be in my view model? MVVM

I'm refactoring a silverlight LOB application to use MVVM..

On one of my controls i have a few animations which currently get triggered in the codebehind once the data is loaded..

This is view specific data and since the viewmodel is supposed to be somewhat headless (not dependant on view objects like the animations)..

Where should this c开发者_如何学JAVAode be?

Thanks


A DataTrigger, a DataTrigger! My kingdom for a DataTrigger!

In WPF, you can trigger animations based on data in your ViewModel. In Silverlight, they use the VSM...I still haven't bothered to learn how this is done. Apparently the Blend Behavior SDK (which you can download separately) provides a DataTrigger approximation that fires of a VSM go to behavior based on a binding. This stackoverflow question (not the accepted answer but the one by Mike Post) shows how to do it...and a follow up answer shows how to do it without Blend.


In short, you can rig up your animation trigger to a data trigger -- no code-behind needed. Other View technologies (not WPF or Silverlight) will require you to add a "data load complete" event to the ViewModel.

MVVM is simply MVP with WPF/Silverlight integration, to make signaling things like this easier. I believe WPF includes a data trigger, that may be used to trigger the animation. This allows you to forego adding a "data load complete" event to the ViewModel. You COULD add the event now, but you may be wasting your time, preparing the code for MVP compatibility that may never be needed.

The purpose of MVVM and MVP is to make the presentation view interchangeable. Consider how a WinForms, WinCE, text-only terminal (or even text to speech) View should inform the user the data are loaded. Each technology will behave differently. Therefore, the act of altering the user interface should reside in the View's code-behind, when not using WPF or Silverlight.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜