WPF使用RepeatBehavior停止ColorAnimation

时间:2013-10-15 12:42:37

标签: wpf animation

我在停止动画方面遇到了一些问题,它只是永远存在。我认为RepeatBehavior应该控制它,但它似乎不起作用。

<Grid.Style>
    <Style TargetType="Grid">
        <Style.Triggers>
            <DataTrigger Binding="{Binding IsNew}" Value="true">
                <DataTrigger.EnterActions>
                    <BeginStoryboard>
                        <Storyboard>
                            <ColorAnimation RepeatBehavior="1"
                                Storyboard.TargetProperty="Background.(SolidColorBrush.Color)"
                                To="LightGreen" Duration="0:0:0.25" AutoReverse="True" >
                            </ColorAnimation>
                        </Storyboard>
                    </BeginStoryboard>
                </DataTrigger.EnterActions>
            </DataTrigger>
            <DataTrigger Binding="{Binding IsNew}" Value="false">
                <Setter Property="Background" Value="WhiteSmoke"></Setter>
            </DataTrigger>
        </Style.Triggers>
    </Style>
</Grid.Style>

1 个答案:

答案 0 :(得分:3)

解决方案正在使用

RepeatBehavior="1x"

所以 1x 不仅仅是 1 ,对我来说不合逻辑,但可能有原因......

更新(从@clemens输入后):

根据MSDN,XAML属性用法是:

<object property="iterationCountx"/>
- or -
<object property="[days.]hours:minutes:seconds[.fractionalSeconds]"/>
- or -
<object property="[days.]hours:minutes"/>
- or -
<object property="days"/>
- or -
<object property="Forever"/>

这更有意义,但不是很直观..

<Grid.Style>
    <Style TargetType="Grid">
        <Style.Triggers>
            <DataTrigger Binding="{Binding IsNew}" Value="true">
                <DataTrigger.EnterActions>
                    <BeginStoryboard>
                        <Storyboard>
                            <ColorAnimation RepeatBehavior="1x"
                                Storyboard.TargetProperty="Background.(SolidColorBrush.Color)"
                                To="LightGreen" Duration="0:0:0.25" AutoReverse="True" >
                            </ColorAnimation>
                        </Storyboard>
                    </BeginStoryboard>
                </DataTrigger.EnterActions>
            </DataTrigger>
            <DataTrigger Binding="{Binding IsNew}" Value="false">
                <Setter Property="Background" Value="WhiteSmoke"></Setter>
            </DataTrigger>
        </Style.Triggers>
    </Style>
</Grid.Style>