Receive Notification When an Animation Completes
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="" Height="300" Width="300" Background="Black">
<Window.Triggers>
<EventTrigger RoutedEvent="Window.Loaded">
<BeginStoryboard>
<Storyboard Completed="Storyboard_Completed">
<ParallelTimeline Completed="ParallelTimeline_Completed">
<ColorAnimation Duration="0:0:1" Completed="Animation1_Completed" Storyboard.TargetProperty="Background.Color" To="White" />
<ColorAnimation Duration="0:0:2" Completed="Animation2_Completed" Storyboard.TargetName="bd" Storyboard.TargetProperty="Background.(SolidColorBrush.Color)" To="Black" />
</ParallelTimeline>
<ColorAnimation Duration="0:0:3" Completed="Animation3_Completed" Storyboard.TargetName="rect" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" To="Firebrick" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Window.Triggers>
<Border x:Name="bd" Margin="20" Background="HotPink">
<Rectangle x:Name="rect" Width="100" Height="100" Fill="WhiteSmoke" />
</Border>
</Window>
//File:Window.xaml.vb
Imports System
Imports System.Windows
Namespace WpfApplication1
Public Partial Class Window1
Inherits Window
Public Sub New()
InitializeComponent()
End Sub
Private Sub Storyboard_Completed(sender As Object, e As EventArgs)
MessageBox.Show("Storyboard complete.", "WpfApplication1")
End Sub
Private Sub ParallelTimeline_Completed(sender As Object, e As EventArgs)
MessageBox.Show("ParallelTimeline complete.", "WpfApplication1")
End Sub
Private Sub Animation1_Completed(sender As Object, e As EventArgs)
MessageBox.Show("Animation 1 complete.", "WpfApplication1")
End Sub
Private Sub Animation2_Completed(sender As Object, e As EventArgs)
MessageBox.Show("Animation 2 complete.", "WpfApplication1")
End Sub
Private Sub Animation3_Completed(sender As Object, e As EventArgs)
MessageBox.Show("Animation 3 complete.", "WpfApplication1")
End Sub
End Class
End Namespace
Related examples in the same category