WPF: Activate Trigger when a MVVM bound property changes
Asked Answered
M

1

3

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

Mayhew answered 4/3, 2010 at 0:52 Comment(0)
C
3

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.

Campo answered 4/3, 2010 at 1:21 Comment(2)
Thank you Reed - your suggestion was ultimately the correct way to go. Actually I had tried the exact same approach before but having run into the problem described at: sweux.com/blogs/smoura/index.php/wpf/2009/07/08/… (one DataTrigger overriding the previous one) so it seemed to me like the error was further down the execution chain. The solution suggested in the above link worked to fix the general approach to use DataTriggers in a linked style.Mayhew
Documented link does not exist any more.Debose

© 2022 - 2024 — McMap. All rights reserved.