Stella
Stella

Reputation: 548

Animating a DropShadowEffect on a control

I'm trying to create a very simple animation where I animate the DropShadowEffect on a control using C#. From my little understanding of WPF I believed it was done this way;

        DoubleAnimation da = new DoubleAnimation();
        da.From = 10;
        da.To = 50;
        da.Duration = TimeSpan.FromSeconds(1);
        progressBar1.BeginAnimation(DropShadowEffect.BlurRadiusProperty, da);

It's a bright colored glow on a black background so I'm sure the glow is there and not moving. I've tried applying it to different controls as well. Am I missing something obvious? But the code does absolutely nothing. I get no error either. I would appreciate any help.

Upvotes: 0

Views: 183

Answers (1)

Flat Eric
Flat Eric

Reputation: 8111

You have to call the BeginAnimation function on the effect and not on the control:

This is the XAML:

<ProgressBar Width="200" Height="30" Name="progressBar1">
    <ProgressBar.Effect>
        <DropShadowEffect Color="Black" x:Name="effect" >

        </DropShadowEffect>
    </ProgressBar.Effect>
</ProgressBar>

And here is the Code:

DoubleAnimation da = new DoubleAnimation();
da.From = 10;
da.To = 50;
da.Duration = TimeSpan.FromSeconds(1);
effect.BeginAnimation(DropShadowEffect.BlurRadiusProperty, da);

Upvotes: 2

Related Questions