The Color property of the SolidColorBrush used to fill this rectangle is animated

image_pdfimage_print


   
 

<Window x:Class="Workspace.DockExample"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Workspace" Width="640" Height="480">
   <StackPanel>
      <Rectangle 
        Width="100" Height="50" Stroke="Black" StrokeThickness="1"
        Margin="10" HorizontalAlignment="Center"
        Grid.Column="0" Grid.Row="1">
        <Rectangle.Fill>
          <SolidColorBrush x:Name="solidColorBrush1" Color="Blue" />
        </Rectangle.Fill>
      </Rectangle>

      <Button Grid.Column="0" Grid.Row="2"
        HorizontalAlignment="Center">
        Start Animation
        <Button.Triggers>
          <EventTrigger RoutedEvent="Button.Click">
            <BeginStoryboard>
              <Storyboard>
                <ColorAnimation Storyboard.TargetName="solidColorBrush1"
                  Storyboard.TargetProperty="Color"
                  From="Blue" To="Red" Duration="0:0:10" />
              </Storyboard>
            </BeginStoryboard>
          </EventTrigger>
        </Button.Triggers>
      </Button>

   
   </StackPanel>
</Window>