cyrus-d
cyrus-d

Reputation: 843

WPF ColorAnimation inside Window.Resources

I have a TextBlock that I would like to give it a color animation effect; I have done something like this:

<Window.Resources>
    <Storyboard x:Key="AnimateTarget" RepeatBehavior="Forever">

        <ColorAnimation AutoReverse="False" Duration="0:0:5" From="Red" To="black" Storyboard.TargetName="txtBarcode" AccelerationRatio="1" Storyboard.TargetProperty="(TextBlock.Background).(SolidColorBrush.Color)" FillBehavior="HoldEnd">

        </ColorAnimation>
    </Storyboard>
</Window.Resources>

I start the animation from code behind:

((Storyboard)this.Resources["AnimateTarget"]).Begin();

but when i start the animation its give me the following error:

'Background' property does not point to a DependencyObject in path '(0).(1)'.

I would priciest if someone helps me on this,

Thanks,

Upvotes: 2

Views: 786

Answers (1)

LPL
LPL

Reputation: 17083

Give your TextBlock any Background and it will work.

<TextBlock Name="txtBarcode"
           Background="Transparent"

Probably Background is Null and so there is no DependencyObject to animate.

Upvotes: 2

Related Questions