Ben
Ben

Reputation: 1

How to animate opacity of dropshadoweffect in C# code?

How do I go about animating the opacity of a dropshadoweffect in code. I am dynamically creating stackpanels in my UI which contain an image and a text block. I have applied a dropshadoweffect to the image, which I would like to animate the opacity. Here's what I have:

Image img = ch.ChannelLogo;  //Create the image for the button
img.Height = channelStackPnl.Height * .66;

DropShadowEffect dSE = new DropShadowEffect();
dSE.Color = Colors.White;
dSE.Direction = 25;
dSE.ShadowDepth = 10;
dSE.Opacity = .40;
img.Effect = dSE;

DoubleAnimation animateOpacity = new DoubleAnimation();
animateOpacity.From = 0;
animateOpacity.To = 1;
animateOpacity.AutoReverse = true;
animateOpacity.RepeatBehavior = RepeatBehavior.Forever;
animateOpacity.Duration = new Duration(new TimeSpan(0, 0, 0, 0, 400));

//Here's where I am stuck.  How do I specifically target the opacity of the effect propery?
img.BeginAnimationimg.BeginAnimation(DropShadowEffect.OpacityProperty,animateOpacity);

Upvotes: 0

Views: 1779

Answers (1)

brunnerh
brunnerh

Reputation: 185445

dSE.BeginAnimation(DropShadowEffect.OpacityProperty, animateOpacity);

Probably...

(You are animating the effect, not the image)

Upvotes: 1

Related Questions