<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Simple Animation" Height="165" Width="428">
<StackPanel Margin="20">
<Rectangle Name="SimpleGreenRectangle" Fill="Green" Width="50" Height="30" />
<StackPanel Orientation="Vertical" Margin="0,20,0,0">
<Button Name="startButton">Start</Button>
<Button Name="stopButton">Stop</Button>
<StackPanel.Triggers>
<EventTrigger SourceName="startButton" RoutedEvent="Button.Click">
<BeginStoryboard Name="myStoryboard">
<Storyboard>
<DoubleAnimation Storyboard.TargetName="SimpleGreenRectangle"
Storyboard.TargetProperty="Width"
From="50" To="300" Duration="0:0:2" RepeatBehavior="Forever" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
<EventTrigger SourceName="stopButton" RoutedEvent="Button.Click">
<StopStoryboard BeginStoryboardName="myStoryboard" />
</EventTrigger>
</StackPanel.Triggers>
</StackPanel>
</StackPanel>
</Window>