Can anyone help me trying to find out why this doesn't work.
The brushes variable contains a pre-filled list of brushes.
If I try to apply the BeginAnimation
directly during the iteration, it works fine. But has a great overhead starting each animation separately...
So I was trying to put all the animations in a single storyboard, and fire them all at once...
var storyBoard = new Storyboard();
var duration = new Duration(TimeSpan.FromMilliseconds(time));
foreach (Brush brush in brushes)
{
var animation = new DoubleAnimation(toValue, duration);
storyBoard.Children.Add(animation);
Storyboard.SetTargetProperty(animation, new PropertyPath(Brush.OpacityProperty));
Storyboard.SetTarget(animation, brush);
}
storyBoard.Begin();
This code simply does nothing (that I can see...).
Edit: Still not sure of what is problem with the SetTarget method, either a bug or I'm just not using as it should be. Anyway I solved the problem generating unique names for my brushes at runtime and using the SetTargetName method.