Control the Progress of an Animation : Animation « Windows Presentation Foundation « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Design Patterns
8.Development Class
9.Event
10.File Stream
11.Generics
12.GUI Windows Form
13.Language Basics
14.LINQ
15.Network
16.Office
17.Reflection
18.Regular Expressions
19.Security
20.Services Event
21.Thread
22.Web Services
23.Windows
24.Windows Presentation Foundation
25.XML
26.XML LINQ
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp » Windows Presentation Foundation » AnimationScreenshots 
Control the Progress of an Animation
Control the Progress of an Animation
  

<Window x:Class="WpfApplication1.Window1"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  Title="" Height="300" Width="600">
    <Grid>
        <Rectangle x:Name="Rectangle" Height="100" Width="100" Fill="Firebrick">
            <Rectangle.RenderTransform>
                <MatrixTransform x:Name="RectangleMatrixTransform" />
            </Rectangle.RenderTransform>

            <Rectangle.Triggers>
                <EventTrigger RoutedEvent="Rectangle.Loaded">
                    <BeginStoryboard x:Name="RectangleStoryboard">
                        <Storyboard x:Name="Storyboard" CurrentTimeInvalidated="Storyboard_Changed">
                            <MatrixAnimationUsingPath Storyboard.TargetName="RectangleMatrixTransform" Storyboard.TargetProperty="Matrix" Duration="0:0:10"
                RepeatBehavior="Forever">
                                <MatrixAnimationUsingPath.PathGeometry>
                                    <PathGeometry Figures="M -100,0 300, 0" />
                                </MatrixAnimationUsingPath.PathGeometry>
                            </MatrixAnimationUsingPath>
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </Rectangle.Triggers>
        </Rectangle>

        <Slider x:Name="Seeker" Minimum="0" Maximum="1" SmallChange="0.001" ValueChanged="Seeker_ValueChanged">
            <Slider.Triggers>
                <EventTrigger RoutedEvent="Slider.MouseLeftButtonDown">
                    <StopStoryboard BeginStoryboardName="RectangleStoryboard" />
                </EventTrigger>
                <EventTrigger RoutedEvent="Slider.MouseLeftButtonUp">
                    <ResumeStoryboard BeginStoryboardName="RectangleStoryboard" />
                </EventTrigger>
            </Slider.Triggers>
        </Slider>
    </Grid>
</Window>

//File:Window.xaml.cs
using System;
using System.Windows;
using System.Windows.Media.Animation;
using System.Windows.Input;

namespace WpfApplication1
{
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
        }
        private void Storyboard_Changed(object sender, System.EventArgs e)
        {
            ClockGroup clockGroup = sender as ClockGroup;
            AnimationClock animationClock = clockGroup.Children[0as AnimationClock;
            if (animationClock.CurrentProgress.HasValue)
            {
                Seeker.Value = animationClock.CurrentProgress.Value;
            }
        }
        private void Seeker_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            Storyboard.Seek(Rectangle,
                            TimeSpan.FromTicks((long)(Storyboard.Children[0].Duration.TimeSpan.Ticks * Seeker.Value)),
                            TimeSeekOrigin.BeginTime);
        }
    }
}

   
    
  
Related examples in the same category
1.Two AnimationsTwo Animations
2.Bouncing BallBouncing Ball
3.Animation along a pathAnimation along a path
4.Animate RadialGradientAnimate RadialGradient
5.Animate RenderTransform AngleAnimate RenderTransform Angle
6.Animate OpacityAnimate Opacity
7.Animation In StyleAnimation In Style
8.Animation without acceleration or decelerationAnimation without acceleration or deceleration
9.Animation with a fast speedAnimation with a fast speed
10.Animation with a slow speedAnimation with a slow speed
11.Animation that accelerates through 50% of its durationAnimation that accelerates through 50% of its duration
12.Animation that decelerates through 50% of its durationAnimation that decelerates through 50% of its duration
13.Animate the brush's RadiusX property.Animate the brush's RadiusX property.
14.Animate Fill.RadiusYAnimate Fill.RadiusY
15.Animate GradientStop and Button controlAnimate GradientStop and Button control
16.Animate EndPointAnimate EndPoint
17.Animate StartPointAnimate StartPoint
18.Animate Ellipse RadiusY, RadiusXAnimate Ellipse RadiusY, RadiusX
19.XAML Only AnimationXAML Only Animation
20.Animation with Discrete Key FramesAnimation with Discrete Key Frames
21.Animation with Mixed Key Frames.xamlAnimation with Mixed Key Frames.xaml
22.Control Animations Through TriggersControl Animations Through Triggers
23.Animate the Color of a Brush with Indirect Property TargetingAnimate the Color of a Brush with Indirect Property Targeting
24.Animate the background colorAnimate the background color
25.Animate Width and Height of a EllipseAnimate Width and Height of a Ellipse
26.Animate Width and Height of a RectangleAnimate Width and Height of a Rectangle
27.Use ColorAnimationUsingKeyFrames to animate the foreground color of a TextBlockUse ColorAnimationUsingKeyFrames to animate the foreground color of a TextBlock
28.Use StringAnimationUsingKeyFrames to animate the text value of a TextBlockUse StringAnimationUsingKeyFrames to animate the text value of a TextBlock
29.Four Sided BounceFour Sided Bounce
30.Discrete Double Key FrameDiscrete Double Key Frame
31.Simple Path AnimationSimple Path Animation
32.Start the animation with Path is loadedStart the animation with Path is loaded
33.Matrix Animated ButtonMatrix Animated Button
34.Bouncing Ball with ParallelTimelineBouncing Ball with ParallelTimeline
35.Bouncing Ball with DoubleAnimationBouncing Ball with DoubleAnimation
36.KeySpline AnimationKeySpline Animation
37.Ball moves in a constant speedBall moves in a constant speed
38.Ball moves following spline key framesBall moves following spline key frames
39.Repetition countRepetition count
40.Repetition durationRepetition duration
41.Use ColorAnimationUsingKeyFrames to animate GradientStopUse ColorAnimationUsingKeyFrames to animate GradientStop
42.Use StringAnimationUsingKeyFrames to ColorUse StringAnimationUsingKeyFrames to Color
43.Using DiscreteStringKeyFrameUsing DiscreteStringKeyFrame
44.Animate Ball HeightAnimate Ball Height
45.Rotate Button AnimationRotate Button Animation
46.Rotate Button Animation With LayoutRotate Button Animation With Layout
47.A simple, finite animationA simple, finite animation
48.Code Animation Accelerate DecelerateCode Animation Accelerate Decelerate
49.Animation with codeAnimation with code
50.Velocity animationVelocity animation
51.Animation In CodeAnimation In Code
52.A Simple Animation in CodeA Simple Animation in Code
53.Remove Animations with AnimationClockRemove Animations with AnimationClock
54.Remove AnimationsRemove Animations
55.Markup for navigation transition animations
56.Opacity AnimationOpacity Animation
57.Width and Height animationWidth and Height animation
58.Timer triggered AnimationTimer triggered Animation
59.Path animation by code, duration, RepeatBehaviorPath animation by code, duration, RepeatBehavior
60.Rolling Ball AnimationRolling Ball Animation
61.Show a Continuous Animation During an Asynchronous ProcessShow a Continuous Animation During an Asynchronous Process
62.Receive Notification When an Animation CompletesReceive Notification When an Animation Completes
63.An animated Ellipse traces the outline of rendered text by using the path geometry of the text.An animated Ellipse traces the outline of rendered text by using the path geometry of the text.
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.