Mega Code Archive
Remove Animations with AnimationClock
//File:Window.xaml.cs
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Animation;
namespace WpfApplication1
{
public partial class Window1 : Window
{
private AnimationClock opacityClock;
private AnimationClock widthClock;
public Window1()
{
InitializeComponent();
}
private void Button3_Loaded(object sender, RoutedEventArgs e)
{
DoubleAnimation opacityAnimation = new DoubleAnimation(1d, 0.5d, TimeSpan.FromSeconds(1), FillBehavior.HoldEnd);
opacityAnimation.RepeatBehavior = RepeatBehavior.Forever;
opacityAnimation.AutoReverse = true;
opacityClock = opacityAnimation.CreateClock();
button3.ApplyAnimationClock(Button.OpacityProperty, opacityClock);
DoubleAnimation widthAnimation = new DoubleAnimation(140d, 50d, TimeSpan.FromSeconds(1), FillBehavior.HoldEnd);
widthAnimation.RepeatBehavior = RepeatBehavior.Forever;
widthAnimation.AutoReverse = true;
widthClock = widthAnimation.CreateClock();
button3.ApplyAnimationClock(Button.WidthProperty, widthClock);
}
private void Button3_Click(object sender, RoutedEventArgs e)
{
opacityClock.Controller.Remove();
widthClock.Controller.Remove();
}
}
}