How to stop an animation WPF?

后端 未结 2 1340
暖寄归人
暖寄归人 2021-01-06 12:47

How to stop an animation so it won\'t produce Completed event. Here\'s simple example



        
相关标签:
2条回答
  • 2021-01-06 13:10

    you can use this:

    <Border Width="20" Height="20" Background="Red" x:Name="border" >
                    <Border.Triggers>
                        <EventTrigger RoutedEvent="MouseEnter">
                            <BeginStoryboard Name="Ali">
                                <Storyboard>
                                    <DoubleAnimation To="0" Duration="0:0:4" Completed="com" Storyboard.TargetProperty="Opacity"/>
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger>
                        <EventTrigger RoutedEvent="MouseLeave">
                            <StopStoryboard  BeginStoryboardName="Ali"/>
                        </EventTrigger>
                    </Border.Triggers>
                </Border>
    

    and :

    private void com(object sender, EventArgs e)
            {
                MessageBox.Show("boom!");
            }
    
    0 讨论(0)
  • 2021-01-06 13:10

    You could use Property or Data Trigger's EnterActions and ExitActions properties or as @Ali said correctly use Begin and Stop storyboard.

    0 讨论(0)
提交回复
热议问题