WPF: Activate Trigger when a MVVM bound property changes

霸气de小男生 提交于 2019-12-23 16:09:30

问题


somehow I am going in circles here. Please forgive me if the answer to this question is obvious.

I want to react to changed properties in the ViewModel in the View. When the properties (bool) change the View should start an animation (BeginStoryBoard). Actually in my application there are 4 of these properties each with its own name in the VM and two desired animations each (hide/show) for the respective 4 container view elements.

When setting these Triggers (tried DataTrigger/Trigger/EventTrigger) directly in the respective container elements (all of them of custom type SizerControl derived from ContentConrol) wpf gave me errors suggesting using a style. When setting a style directly in the container elements I got: "The tag 'Style.Triggers' does not exist in XML namespace ..." But when using a style in a global ResourceDictionary I am at a loss how to bind to the 4 containersto get the "input" value for the trigger.

Do you have a suggestion how to solve this from an architecture pov? Maybe I am already down too far the wrong path to see the obvious solution.

Thanks a bunch, Hinnerk


回答1:


You can do this with a DataTrigger and a StoryBoard.

MSDN has a full sample describing the process, with code, documented in How to: Trigger an Animation When Data Changes.



来源:https://stackoverflow.com/questions/2376173/wpf-activate-trigger-when-a-mvvm-bound-property-changes

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