Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

Int64Animation Class

Animates the value of a Int64 property between two target values using linear interpolation over a specified Duration.

Namespace: System.Windows.Media.Animation
Assembly: PresentationCore (in presentationcore.dll)
XML Namespace:  http://schemas.microsoft.com/winfx/2006/xaml/presentation

public class Int64Animation : Int64AnimationBase
public class Int64Animation extends Int64AnimationBase
public class Int64Animation extends Int64AnimationBase
<Int64Animation .../>

An animation updates the value of a property over a period of time. An animation effect can be subtle, such as moving a Shape a few pixels left and right, or dramatic, such as enlarging an object to 200 times its original size while spinning it and changing its color. To create an animation in Windows Presentation Foundation (WPF), you associate an animation with an object's property value.

Target Values

The Int64Animation class creates a transition between two target values. To set its target values, use its From, To, and By properties.  The following table summarizes how the From, To, and By properties may be used together or separately to determine an animation's target values.

Properties specified

Resulting behavior

From

The animation progresses from the value specified by the From property to the base value of the property being animated or to a previous animation's output value, depending on how the previous animation is configured.

From and To

The animation progresses from the value specified by the From property to the value specified by the To property.

From and By

The animation progresses from the value specified by the From property to the value specified by the sum of the From and By properties.

To

The animation progresses from the animated property's base value or a previous animation's output value to the value specified by the To property.

By

The animation progresses from the base value of the property being animated or a previous animation's output value to the sum of that value and the value specified by the By property.

NoteNote:

If you set both the To and By properties, the To property takes precedence and the By property is ignored.

To use other interpolation methods or animate between more than two target values, use a Int64AnimationUsingKeyFrames object.

For information about applying multiple animations to a single property, see KeyFrame Animations.

Freezable Features

Because the Int64Animation class inherits from Freezable, Int64Animation objects gain several special features, which include the following: they can be declared as resources, shared among multiple objects, made read-only to improve performance, cloned, and made thread-safe. For more information about the different features provided by Freezable objects, see the Freezable Objects Overview.

This example shows one way to apply an animation to a property without using a Storyboard.

NoteNote:

This functionality is not available in Extensible Application Markup Language (XAML). For information about animating a property in XAML, see How to: Animate a Property by Using a Storyboard.

To apply a local animation to a property, use the BeginAnimation method. This method takes two parameters: a DependencyProperty that specifies the property to animate, and the animation to apply to that property.

The following example shows how to animate the width and background color of a Button.

/*

   This sample demonstrates how to apply non-storyboard animations to a property.
   To animate in markup, you must use storyboards.

*/

using System;
using System.Windows;
using System.Windows.Navigation;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Controls;

namespace Microsoft.Samples.Animation.LocalAnimations
{

    // Create the demonstration.
    public class LocalAnimationExample : Page 
    {
        
        

        
        public LocalAnimationExample()
        {
        
            
            WindowTitle = "Local Animation Example";
            StackPanel myStackPanel = new StackPanel();
            myStackPanel.Margin = new Thickness(20);                     
    
    
            // Create and set the Button.
            Button aButton = new Button();
            aButton.Content = "A Button";

            // Animate the Button's Width.
            DoubleAnimation myDoubleAnimation = new DoubleAnimation();
            myDoubleAnimation.From = 75;
            myDoubleAnimation.To = 300;
            myDoubleAnimation.Duration =  new Duration(TimeSpan.FromSeconds(5));
            myDoubleAnimation.AutoReverse = true;
            myDoubleAnimation.RepeatBehavior = RepeatBehavior.Forever;
            
            // Apply the animation to the button's Width property.
            aButton.BeginAnimation(Button.WidthProperty, myDoubleAnimation);       

            // Create and animate a Brush to set the button's Background.
            SolidColorBrush myBrush = new SolidColorBrush();
            myBrush.Color = Colors.Blue;            

            ColorAnimation myColorAnimation = new ColorAnimation();
            myColorAnimation.From = Colors.Blue;
            myColorAnimation.To = Colors.Red;
            myColorAnimation.Duration =  new Duration(TimeSpan.FromMilliseconds(7000));
            myColorAnimation.AutoReverse = true;
            myColorAnimation.RepeatBehavior = RepeatBehavior.Forever;

            // Apply the animation to the brush's Color property.
            myBrush.BeginAnimation(SolidColorBrush.ColorProperty, myColorAnimation);           
            aButton.Background = myBrush;

            // Add the Button to the panel.
            myStackPanel.Children.Add(aButton);
            this.Content = myStackPanel;
        }
    }
    
}

For the complete sample, see Local Animations Sample.

A variety of animation classes in the System.Windows.Media.Animation namespace exist for animating different types of properties. For more information about animating properties, see Animation Overview. For more information about dependency properties (the type of properties that are shown in these examples) and their features, see Properties Overview.

There are other ways to animate without using Storyboard objects; for more information, see the Property Animation Techniques Overview.

More Code

How to: Animate a Property by Using a Storyboard

This example shows how to use a Storyboard to animate properties. To animate a property by using a Storyboard, create an animation for each property that you want to animate and also create a Storyboard to contain the animations.

How to: Control an Animation using From, To, and By

A "From/To/By" or "basic animation" creates a transition between two target values (see Animation Overview for an introduction to different types of animations). To set the target values of a basic animation, use its From, To, and By properties. The following table summarizes how the From, To, and By properties may be used together or separately to determine an animation's target values.

System.Object
   System.Windows.Threading.DispatcherObject
     System.Windows.DependencyObject
       System.Windows.Freezable
         System.Windows.Media.Animation.Animatable
           System.Windows.Media.Animation.Timeline
             System.Windows.Media.Animation.AnimationTimeline
               System.Windows.Media.Animation.Int64AnimationBase
                System.Windows.Media.Animation.Int64Animation
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.