本文介绍了WPF使用RepeatBehavior停止ColorAnimation的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在停止动画时遇到一些问题,它会一直持续下去。我认为RepeatBehavior应该可以控制此操作,但是它似乎不起作用。

I have some problems with stopping my animation, it just goes on forever. I would think that the RepeatBehavior should control this, but it does not seem to work.

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


推荐答案

解决方案正在使用

RepeatBehavior="1x"

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

So 1x not just 1, not very logical to me, but there probably is a reason..

更新(在@clemens输入之后):

Update (after input from @clemens):

根据MSDN,XAML属性的用法是:

According to MSDN the XAML Attribute Usage is:

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

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

That makes a lot more sense, but not very intuitive..

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

这篇关于WPF使用RepeatBehavior停止ColorAnimation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 02:30