Storyboard animation in WPF
I have written an animation in WPF storyboard: The following is the code:
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
<window x:class="animfromcodebehindWpfApplication1.MainWindow" xmlns:x="#unknown">
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<window.resources>
<storyboard x:key="Storyboard1">
<doubleanimationusingkeyframes storyboard.targetproperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)" storyboard.targetname="rectangle1">
<easingdoublekeyframe keytime="0:0:1" value="-36" />
</doubleanimationusingkeyframes>
<doubleanimationusingkeyframes storyboard.targetproperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)" storyboard.targetname="rectangle1">
<easingdoublekeyframe keytime="0:0:1" value="-46" />
</doubleanimationusingkeyframes>
<doubleanimationusingkeyframes storyboard.targetproperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)" storyboard.targetname="rectangle1">
<easingdoublekeyframe keytime="0:0:1" value="359.484" />
</doubleanimationusingkeyframes>
</storyboard>
</window.resources>
<window.triggers>
<eventtrigger routedevent="FrameworkElement.Loaded">
<beginstoryboard storyboard="{StaticResource Storyboard1}" />
</eventtrigger>
</window.triggers>
<grid>
<rectangle height="100" horizontalalignment="Left" margin="84,82,0,0" name="rectangle1" stroke="Black" verticalalignment="Top" width="200" fill="#FDFFFF0D" rendertransformorigin="0.5,0.5">
<rectangle.rendertransform>
<transformgroup>
<scaletransform />
<skewtransform />
<rotatetransform />
<translatetransform />
</transformgroup>
</rectangle.rendertransform>
</rectangle>
<Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="344,72,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />
</grid>
</window>
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
In the code behind I have written
public void AnimateRectangle()
{
Storyboard rectrotate = (Storyboard)FindResource("Storyboard1");
rectrotate.Begin();
}
I call this function on button click event.
When I click the button nothing happens.
Addition : The storyboard animates when the window loads but not on clicking the button. Please help
Please help.
EDIT: Fixed code markup with tags.