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.cs
using System;
using System.Windows;
namespace WpfApplication1
{
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
private void Storyboard_Completed(object sender, EventArgs e)
{
MessageBox.Show("Storyboard complete.", "WpfApplication1");
}
private void ParallelTimeline_Completed(object sender, EventArgs e)
{
MessageBox.Show("ParallelTimeline complete.", "WpfApplication1");
}
private void Animation1_Completed(object sender, EventArgs e)
{
MessageBox.Show("Animation 1 complete.", "WpfApplication1");
}
private void Animation2_Completed(object sender, EventArgs e)
{
MessageBox.Show("Animation 2 complete.", "WpfApplication1");
}
private void Animation3_Completed(object sender, EventArgs e)
{
MessageBox.Show("Animation 3 complete.", "WpfApplication1");
}
}
}
Related examples in the same category