So far you have seen how the Forever value for
RepeatBehavior of an animation causes it to run forever. You can change this
behavior with other values and also reverse your animations by setting their
AutoReverse attribute to true.
In addition to Forever value for RepeatBehavior, you can specify
the number of iterations. Listing 4 is an animation that changes the width of
a Button from 100 to 200 in five seconds, but twice (it is a modified version
of Listing 3). It also reverses itself. The result is shown in Figure 10,
Figure 11 and Figure 12.
Listing 4
<Window x:Class="AnimationsInXAML.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Animations In XAML" Height="180" Width="300"
>
<StackPanel>
<StackPanel.Triggers>
<EventTrigger RoutedEvent="Rectangle.MouseEnter">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard Storyboard.TargetName="btnSend"
Storyboard.TargetProperty="Width">
<DoubleAnimation From="100"
To="200"
Duration="0:0:5"
RepeatBehavior="2x"
AutoReverse="True"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</StackPanel.Triggers>
<Button Name="btnSend"
Width="100"
Height="40"
Margin="40"
Background="Plum">
ASP Alliance
</Button>
</StackPanel>
</Window>
Figure 10

Figure 11

Figure 12
