Window.Resources中的WPF ColorAnimation

时间:2012-06-22 11:29:17

标签: wpf xaml animation effects coloranimation

我有一个TextBlock,我想给它一个彩色动画效果;我做过类似的事情:

<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>

我从后面的代码开始动画:

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

但是当我开始动画时,它会给我以下错误:

'Background'属性不指向路径'(0)。(1)'中的DependencyObject。

如果有人帮助我,我会比较贵,

谢谢,

1 个答案:

答案 0 :(得分:2)

TextBlock任意Background提供给它{}}。

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

可能BackgroundNull,因此没有动态DependencyObject