Proper way in MVVM to drive visual states

冷暖自知 提交于 2019-12-22 18:50:10

问题


Given a content presenter that can display one of 4 different application pages, and I want to fade/otherwise animate a transition between pages based on view model state. Ideally I'd like to have these all defined within a DataTemplate, and then trigger transitions based on an enum from the view model, so that when some enum representing state changes, the transitions trigger to the appropriate page.

Is there a known best practice to handle things like this? Immediately coming to mind is the possibiltiy to use Enter and Exit actions on data triggers to play storyboards, but this definately doesn't use the parts and states model, so I'd like to shy away from that. I've also tried using the DataStateSwitchBehavior from the codeplex Expression project, but found it to be incompatable with the latest builds of WPF 4.0/Blend 4 RC's SDK. Does anyone have any ideas on how to handle this elegantly? I'm using the MVVM-Light framework. Also I'd like to point out that as long as this resides on a DataTemplate in a Resource Dictionary, code-behind is not an option without refactoring.


回答1:


Ah,..I remember scratching my head on this one for hours! Scratch no more... It's already been answered here . Good luck.



来源:https://stackoverflow.com/questions/3063808/proper-way-in-mvvm-to-drive-visual-states

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!