WPF: Activate Trigger when a MVVM bound property changes
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开发者_StackOverflow中文版). 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
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.
精彩评论