views:

334

answers:

1

Hi,

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

+2  A: 

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.

Reed Copsey
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:http://sweux.com/blogs/smoura/index.php/wpf/2009/07/08/playing-storyboards-on-datatriggers-to-animate-a-path/(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.
Hinnerk Brügmann