# StoryBoard: Animations in WPF

I recently discovered how to do animations in WPF. It's super simple! So what if you want to create a mouse over animation on a StackPanel? You use the StoryBoard XAML element. Snippet:

 <Storyboard x:Key="mouseFadeIn">
<DoubleAnimation
Duration="0:0:5"
Storyboard.TargetName="myStackPanel"
Storyboard.TargetProperty="(UIElement.Opacity)"
From="0.25"
To="1.0"/>
</StoryBoard>


This will cause a the Opacity of the element to change from 0.25 to 1.0 over a period of 5 seconds. Note: this should be put in the "Resources" tag. So, if it's a Window it would be "Window.Resources" or if it's a UserControl it would be "UserControl.Resources"... Snippet:

<UserControl.Resources>
<StoryBoard key="blah">...


So how do we get this to trigger on a mouse over? By using Triggers of course! Snippet:

<UserControl.Triggers>
<EventTrigger RoutedEvent="Mouse.MouseEnter" SourceName="myStackPanel">