Use ColorAnimationUsingKeyFrames to animate GradientStop : Color « Animations « Silverlight






Use ColorAnimationUsingKeyFrames to animate GradientStop

Use ColorAnimationUsingKeyFrames to animate GradientStop
    

<UserControl x:Class='SilverlightApplication3.MainPage'
    xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' 
    xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
    xmlns:d='http://schemas.microsoft.com/expression/blend/2008' 
    xmlns:mc='http://schemas.openxmlformats.org/markup-compatibility/2006' 
    mc:Ignorable='d' 
    d:DesignWidth='640' 
    d:DesignHeight='480'>
  <StackPanel Margin="15">
    <TextBlock Name="label" 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>
</UserControl>

   
    
    
    
  








Related examples in the same category

1.Color Animation EffectsColor Animation Effects
2.Animate the Color of a Brush with Indirect Property Targeting
3.Animate the background color
4.Color From To By AnimationColor From To By Animation
5.ColorAnimation StoryBoardColorAnimation StoryBoard
6.Use code to control color animationUse code to control color animation
7.Repetition countRepetition count
8.Animate RadialGradient