原来的需求是控件可见时有动画,不可见的时候没有动画,只写了EnterAction,没写ExitAction,以为空间都隐藏了,总不会再有动画了。刚好该动画在一个摄像头获取的视频上面,动画期间视频有点卡,动画隐藏了,视频还是卡,于是弄了一下测试,发现不写ExitAction动画还是在动的。

    <StackPanel>

        <TextBox  Name="tb" Text="1">
        </TextBox>
       
        <Button Focusable="False" Content="Button">
            <Button.RenderTransform>
                <ScaleTransform ScaleX="0.5"></ScaleTransform>
            </Button.RenderTransform>
            <Button.Style>
                <Style TargetType="Button">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding ElementName=tb,Path=Text}" Value="1">
                            <DataTrigger.EnterActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetProperty="(Button.RenderTransform).(ScaleTransform.ScaleX)" From="0.5" To="1" RepeatBehavior="Forever"></DoubleAnimation>
                                    </Storyboard>
                                </BeginStoryboard>
                            </DataTrigger.EnterActions>
                            <DataTrigger.ExitActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetProperty="(Button.RenderTransform).(ScaleTransform.ScaleX)"  To="0.6" ></DoubleAnimation>
                                    </Storyboard>
                                </BeginStoryboard>
                            </DataTrigger.ExitActions>
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </Button.Style>
        </Button>

    </StackPanel>