Mega Code Archive

 
Categories / VB.Net Tutorial / WPF
 

Use EventTrigger elements to animate the MouseEnter and OnMouseLeave events of a Rectangle

<Page    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">   <Page.Resources>     <Style TargetType="Rectangle">       <Setter Property="Width" Value="50" />       <Setter Property="Height" Value="50" />       <Style.Triggers>         <EventTrigger RoutedEvent="MouseEnter">             <BeginStoryboard>                 <Storyboard>                   <DoubleAnimation To="300" Duration="0:0:1.5"                      AccelerationRatio="0.10" DecelerationRatio="0.25"                      Storyboard.TargetProperty="(Canvas.Width)" />                 </Storyboard>             </BeginStoryboard>         </EventTrigger>         <EventTrigger RoutedEvent="MouseLeave">             <BeginStoryboard>                 <Storyboard>                   <DoubleAnimation Duration="0:0:1.5"                      AccelerationRatio="0.10" DecelerationRatio="0.25"                      Storyboard.TargetProperty="(Canvas.Width)" />                 </Storyboard>             </BeginStoryboard>         </EventTrigger>       </Style.Triggers>     </Style>   </Page.Resources>   <StackPanel HorizontalAlignment="Left">     <Rectangle Fill="Red" />   </StackPanel> </Page>