Use ColorAnimationUsingKeyFrames to animate GradientStop : Frame Animation « Windows Presentation Foundation « C# / CSharp Tutorial






<Window x:Class="KeyFrameAnimation"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  Title="Key-Frame Animation" Height="200" Width="300">
  <StackPanel Margin="15">
    <TextBlock Name="label" Block.TextAlignment="Center" Foreground="Blue" />
    <Rectangle Name="rect" Width="200" Height="100" Stroke="Blue" Margin="10">
      <Rectangle.Fill>
        <LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
          <GradientStop Offset="0" />
          <GradientStop Offset="1" />
        </LinearGradientBrush>
      </Rectangle.Fill>
    </Rectangle>
    <StackPanel.Triggers>
      <EventTrigger RoutedEvent="StackPanel.Loaded">
        <EventTrigger.Actions>
          <BeginStoryboard>
            <Storyboard>
              <ColorAnimationUsingKeyFrames
                Storyboard.TargetName="rect"
                Storyboard.TargetProperty="Fill.GradientStops[0].Color"
                RepeatBehavior="Forever">
                <LinearColorKeyFrame Value="#FF00FF" KeyTime="0:0:0" />
                <LinearColorKeyFrame Value="#00805A" KeyTime="0:0:5" />
                <LinearColorKeyFrame Value="#FF0000" KeyTime="0:0:10" />
                <LinearColorKeyFrame Value="#0000FF" KeyTime="0:0:15" />
                <LinearColorKeyFrame Value="#00FFFF" KeyTime="0:0:20" />
                <LinearColorKeyFrame Value="#FF00FF" KeyTime="0:0:25" />
              </ColorAnimationUsingKeyFrames>
            </Storyboard>
          </BeginStoryboard>
        </EventTrigger.Actions>
      </EventTrigger>
    </StackPanel.Triggers>
  </StackPanel>
</Window>
WPF Use Color Animation Using Key Frames To Animate Gradient Stop








24.111.Frame Animation
24.111.1.Animation with Discrete Key FramesAnimation with Discrete Key Frames
24.111.2.Animation with Mixed Key Frames.xamlAnimation with Mixed Key Frames.xaml
24.111.3.Discrete Double Key FrameDiscrete Double Key Frame
24.111.4.Ball moves following spline key framesBall moves following spline key frames
24.111.5.Use ColorAnimationUsingKeyFrames to animate GradientStopUse ColorAnimationUsingKeyFrames to animate GradientStop
24.111.6.Use StringAnimationUsingKeyFrames to ColorUse StringAnimationUsingKeyFrames to Color
24.111.7.Using DiscreteStringKeyFrameUsing DiscreteStringKeyFrame
24.111.8.Use ColorAnimationUsingKeyFrames to animate the foreground color of a TextBlockUse ColorAnimationUsingKeyFrames to animate the foreground color of a TextBlock
24.111.9.Use StringAnimationUsingKeyFrames to animate the text value of a TextBlockUse StringAnimationUsingKeyFrames to animate the text value of a TextBlock