Remove Animations
<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">
<Window.Resources>
<Storyboard x:Key="Storyboard1">
<ParallelTimeline>
<DoubleAnimation x:Name="Animation1" Storyboard.TargetProperty="Width" From="140" To="50"
AutoReverse="True" RepeatBehavior="Forever" />
<DoubleAnimation Storyboard.TargetProperty="Opacity" To="0.5" AutoReverse="True" RepeatBehavior="Forever" />
</ParallelTimeline>
</Storyboard>
</Window.Resources>
<UniformGrid>
<Button Margin="5" Content="Method 2" Click="MyClick">
<Button.Triggers>
<EventTrigger
RoutedEvent="Button.Loaded">
<BeginStoryboard Storyboard="{DynamicResource Storyboard1}" />
</EventTrigger>
</Button.Triggers>
</Button>
</UniformGrid>
</Window>
//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 MyClick(object sender, RoutedEventArgs e)
{
Button button2 = sender as Button;
button2.BeginAnimation(Button.WidthProperty, null);
button2.BeginAnimation(Button.OpacityProperty, null);
}
}
}
Related examples in the same category