如何为LinearGradient的StartPoint设置动画

时间:2011-08-05 10:17:10

标签: wpf animation lineargradientbrush

我有一个用作OpacityMask的LinearGradientBrush,我想让我的动画旋转渐变,所以我试图设置StartPoint和EndPoint的位置动画,但我不能让它工作几个小时:(

    <Style x:Key="NewContentStyle" TargetType="ContentPresenter">
        <Setter Property="OpacityMask">
            <Setter.Value>
                <LinearGradientBrush x:Name="FillGradient"  EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="Black" Offset="0.5"/>
                    <GradientStop Color="Transparent" Offset="1"/>
                </LinearGradientBrush>
            </Setter.Value>
        </Setter>
    </Style>

    <Storyboard x:Key="NewContentStoryboard">
        <PointAnimation Storyboard.TargetProperty="StartPoint" Storyboard.TargetName="FillGradient" From="0.5 0" To="0 0.5" Duration="00:00:1" />
        <PointAnimation Storyboard.TargetProperty="EndPoint" Storyboard.TargetName="FillGradient" From="1 0.5" To="0 0.5" Duration="00:00:1"/>
    </Storyboard>

我收到错误“'FillGradient'名称在'System.Windows.Controls.ContentPresenter'的名称范围内找不到。”

1 个答案:

答案 0 :(得分:3)

请试试这个:

<Storyboard x:Key="NewContentStoryboard">
    <PointAnimation Storyboard.TargetProperty="OpacityMask.(LinearGradientBrush.StartPoint)" From="0.5 0" To="0 0.5" Duration="00:00:1" />
    <PointAnimation Storyboard.TargetProperty="OpacityMask.(LinearGradientBrush.EndPoint)" From="1 0.5" To="0 0.5" Duration="00:00:1"/>
</Storyboard>