Silverlight XAML Primer 12: Using Linear Keyframe Animations: Listing 1.

Using keyframes in a Silverlight canvas to control how an object is animated during a span of time.

<Canvas xmlns="http://schemas.microsoft.com/client/2007">
    <Canvas.Triggers>
      <EventTrigger RoutedEvent="Canvas.Loaded">
        <EventTrigger.Actions>
          <BeginStoryboard>
              <Storyboard Storyboard.TargetName="tbCanvas">
                <DoubleAnimationUsingKeyFrames 
                  Storyboard.TargetProperty="(Canvas.Left)" 
                  Duration="0:0:3" 
                  AutoReverse="True" RepeatBehavior="Forever">
                  <LinearDoubleKeyFrame Value="50" KeyTime="0:0:2" />
                  <LinearDoubleKeyFrame Value="200" KeyTime="0:0:3" />
                </DoubleAnimationUsingKeyFrames> 
              </Storyboard>
          </BeginStoryboard>          
        </EventTrigger.Actions>
      </EventTrigger>
    </Canvas.Triggers>
    <TextBlock Name="tbCanvas" 
     Canvas.Left="0" Canvas.Top="80"
     Foreground="Maroon" FontFamily="Verdana" 
     FontSize="24" FontWeight="Bold"
     Text="Hello, From Silverlight!">
    </TextBlock>
</Canvas>
comments powered by Disqus
Most   Popular
Upcoming Events

.NET Insight

Sign up for our newsletter.

Terms and Privacy Policy consent

I agree to this site's Privacy Policy.