views:

329

answers:

2

I have a a bunch of WPF UserControls that internally trigger some animations upon user interactions. All animations have repeatbehavior = "true" and all animations have the same duration. Now I would like synchronize all those animations on one timeline so they are fading in and out in sync. No matter when the user triggerd the animations. For example if the animations all last 3 secs and the user triggers the 2nd animation 1.5 secs after the first, I still want the animations reach their maximum at the same time. Maybe I can define a global time line in a global resource dictionary that all animations that are defined somewhere in the UserControls can use? Preferably XAML only.

A: 

Simply add all of your animations to a single TimelineCollection. Then add that TimelineCollection to your Storyboard.Children. Then they will all fire simultaneously.

Charlie
AS I said the animations are defined throughout my usercontrols. I don't think there is a way to add animations that are defined in different usercontrols to the same timeline. Or maybe there is?
bitbonk
A: 

XAML: impossible (as far as I know)

code: CompositionTarget.Rendering

ima
Can you elaborate on how I would use the CompositionTarget.Rendering event with my Animation definitions?
bitbonk
You'll have to move animation to code. In Rendering event, check which animations should be running and manually update corresponding properties based on a single timer variable. It's not a lot of work, just a few lines of SomeElement.SomeProperty = baseValue + rate * timePassed;
ima