DoubleAnimationUsingKeyFrames Demo : DoubleAnimationUsingKeyFrames « Animations « Silverlight






DoubleAnimationUsingKeyFrames Demo

DoubleAnimationUsingKeyFrames Demo
    
<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'>
    <UserControl.Resources>
    <Storyboard x:Name="storyBoard1">
      <DoubleAnimationUsingKeyFrames Storyboard.TargetName="textBlock4" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)" BeginTime="00:00:00">
        <SplineDoubleKeyFrame KeyTime="00:00:00.6000000" Value="0"/>
        <SplineDoubleKeyFrame KeyTime="00:00:01.6000000" Value="-175"/>
      </DoubleAnimationUsingKeyFrames>
      <DoubleAnimationUsingKeyFrames Storyboard.TargetName="textBlock4" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)" BeginTime="00:00:00">
        <SplineDoubleKeyFrame KeyTime="00:00:00.6000000" Value="0"/>
        <SplineDoubleKeyFrame KeyTime="00:00:01.6000000" Value="131"/>
      </DoubleAnimationUsingKeyFrames>
      <DoubleAnimationUsingKeyFrames Storyboard.TargetName="textBlock2" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" BeginTime="00:00:00">
        <SplineDoubleKeyFrame KeyTime="00:00:00.2000000" Value="1"/>
        <SplineDoubleKeyFrame KeyTime="00:00:01.2000000" Value="11"/>
      </DoubleAnimationUsingKeyFrames>

    </Storyboard>
  </UserControl.Resources>
  <Grid x:Name="LayoutRoot" Background="White" >
    <MediaElement x:Name="media1" Source="http://localhost:33349/Bear.wmv" Height="250" Width="400" Stretch="Fill" />
    <TextBlock Height="24" HorizontalAlignment="Left" Margin="8,8,0,0" x:Name="textBlock" VerticalAlignment="Top" Width="33" RenderTransformOrigin="0.5,0.5" Foreground="#FF000000" TextWrapping="Wrap">
        <TextBlock.RenderTransform>
          <TransformGroup>
            <ScaleTransform/>
            <SkewTransform/>
            <RotateTransform/>
            <TranslateTransform/>
          </TransformGroup>
        </TextBlock.RenderTransform>
        <Run Text="Test"/>
      </TextBlock>
    <TextBlock Height="24" HorizontalAlignment="Right" Margin="0,0,8,8" x:Name="textBlock2" VerticalAlignment="Bottom" Width="33" RenderTransformOrigin="0.5,0.5" Foreground="#FF000000" TextWrapping="Wrap">
        <TextBlock.RenderTransform>
          <TransformGroup>
            <ScaleTransform/>
            <SkewTransform/>
            <RotateTransform/>
            <TranslateTransform/>
          </TransformGroup>
        </TextBlock.RenderTransform>
        <Run Text="Test"/>
      </TextBlock>
    <TextBlock x:Name="textBlock3" VerticalAlignment="Bottom" Width="33" RenderTransformOrigin="0.5,0.5" Foreground="#FF000000" TextWrapping="Wrap">
        <TextBlock.RenderTransform>
          <TransformGroup>
            <ScaleTransform/>
            <SkewTransform/>
            <RotateTransform/>
            <TranslateTransform/>
          </TransformGroup>
        </TextBlock.RenderTransform>
        <Run Text="Test"/>
      </TextBlock>
    <TextBlock x:Name="textBlock4" VerticalAlignment="Top" Width="33" RenderTransformOrigin="0.5,0.5" Foreground="#FF000000" TextWrapping="Wrap">
        <TextBlock.RenderTransform>
          <TransformGroup>
            <ScaleTransform/>
            <SkewTransform/>
            <RotateTransform/>
            <TranslateTransform/>
          </TransformGroup>
        </TextBlock.RenderTransform>
        <Run Text="Test"/>
      </TextBlock>
    <TextBlock x:Name="timer">0</TextBlock>
  </Grid>
</UserControl>

//File: Page.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace SilverlightApplication3
{
    public partial class MainPage : UserControl
    {

        private long ticks;

        public MainPage()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(Page_Loaded);
        }

        void Page_Loaded(object sender, RoutedEventArgs e)
        {
            media1.MediaEnded += new RoutedEventHandler(media1_MediaEnded);
            storyBoard1.Completed += new EventHandler(storyBoard1_Completed);
            
            storyBoard1.AutoReverse = true;
            storyBoard1.Begin();
        }

        void storyBoard1_Completed(object sender, EventArgs e)
        {
            ticks = DateTime.Now.Ticks - ticks;

            timer.Text = ticks.ToString();

            ticks = DateTime.Now.Ticks;
            storyBoard1.Begin();
        }

        void media1_MediaEnded(object sender, RoutedEventArgs e)
        {
            media1.Position = new TimeSpan(0);
            media1.Play();
        }

    }
}

   
    
    
    
  








Related examples in the same category

1.Animation with DoubleAnimationUsingKeyFramesAnimation with DoubleAnimationUsingKeyFrames
2.DoubleAnimationUsingKeyFrames and SplineDoubleKeyFrameDoubleAnimationUsingKeyFrames and SplineDoubleKeyFrame
3.Use DoubleUsingKeyframes to control animationUse DoubleUsingKeyframes to control animation