Click here to Skip to main content
15,867,756 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I can start the animation via DataTrigger, there is no problem with starting, but when I try to stop that animation via DataTrigger, I does not stop.

And in the code below given, it does not start to animation. Also I try to stop and start animation via DataTrigger with Binding a value. Any suggestions?

What I have tried:

<Border Grid.Row="4" Grid.ColumnSpan="2" BorderThickness="1" Width="140" Height="12" CornerRadius="10" Background="{Binding Machine59.StatusColor}" >
    <Border.Style>
        <Style>
            <Style.Triggers>
                <DataTrigger Binding="{Binding Machine59.HasError}"                        Value="True">
                    <DataTrigger.EnterActions>
                        <BeginStoryboard x:Name="story59_1">
                            <Storyboard>
                                <DoubleAnimation

                 Storyboard.TargetProperty="Opacity"
                                                From="1" To="0"
                                                Duration="0:0:0.5"
                                                AutoReverse="True"
                                                RepeatBehavior="Forever"/>
                            </Storyboard>
                        </BeginStoryboard>
                    </DataTrigger.EnterActions>
                </DataTrigger>
                <DataTrigger Binding="{Binding Machine59.HasError}" Value="False">
                    <DataTrigger.ExitActions>
                        <StopStoryboard BeginStoryboardName="story59_1"/>
                    </DataTrigger.ExitActions>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </Border.Style>
</Border>
Posted
Updated 22-May-22 21:16pm

1 solution

You don't need to create separate DataTrigger entries here. You should have the same DataTrigger for both the EnterActions and the ExitActions.
XML
<Border Grid.Row="4" Grid.ColumnSpan="2" BorderThickness="1" Width="140" Height="12" CornerRadius="10" Background="{Binding Machine59.StatusColor}" >
    <Border.Style>
        <Style>
            <Style.Triggers>
                <DataTrigger Binding="{Binding Machine59.HasError}"                        Value="True">
                    <DataTrigger.EnterActions>
                        <BeginStoryboard x:Name="story59_1">
                            <Storyboard>
                                <DoubleAnimation

                 Storyboard.TargetProperty="Opacity"
                                                From="1" To="0"
                                                Duration="0:0:0.5"
                                                AutoReverse="True"
                                                RepeatBehavior="Forever"/>
                            </Storyboard>
                        </BeginStoryboard>
                    </DataTrigger.EnterActions>
                    <DataTrigger.ExitActions>
                        <StopStoryboard BeginStoryboardName="story59_1"/>
                    </DataTrigger.ExitActions>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </Border.Style>
</Border>
 
Share this answer
 
v2
Comments
[no name] 23-May-22 4:19am    
Thanks for your effort. It works good.
Pete O'Hanlon 23-May-22 4:59am    
You are most welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900