Trigger animation with Rectangle.MouseLeave

image_pdfimage_print


   
     
<Window x:Class="Main"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  Title="" Height="300" Width="300">
  <Grid>
    <Rectangle Height="100" Width="100" Fill="Firebrick" Stroke="Black" StrokeThickness="1">
      <Rectangle.Style>
        <Style TargetType="Rectangle">
          <Style.Triggers>
            <EventTrigger RoutedEvent="Rectangle.MouseLeave">
              <BeginStoryboard>
                <Storyboard>
                  <ParallelTimeline>
                    <DoubleAnimation Storyboard.TargetProperty="Width" To="100" />
                    <DoubleAnimation Storyboard.TargetProperty="Height" To="100" />
                    <ColorAnimation Storyboard.TargetProperty="Fill.Color" To="Red" />
                  </ParallelTimeline>
                </Storyboard>
              </BeginStoryboard>
            </EventTrigger>
          </Style.Triggers>
        </Style>
      </Rectangle.Style>
    </Rectangle>
  </Grid>
</Window>