다음을 통해 공유


방법: 애니메이션 효과가 적용된 속성의 애니메이션 효과가 적용되지 않은 값 가져오기

업데이트: 2007년 11월

개체의 애니메이션 효과가 적용된 속성에서 애니메이션 효과가 적용되지 않은 값을 가져오려면 개체의 GetAnimationBaseValue 메서드를 사용합니다. UIElement, AnimatableContentElement 각각에는 자체 구현이 있습니다.

예제

다음 예제에서는 애니메이션 효과가 적용된 속성의 애니메이션 효과가 적용되지 않은 값을 검색하여 표시합니다.

/*

   This sample shows how to use the 
   Animatable.GetAnimationBaseValue and 
   UIElement.GetAnimationBaseValue methods
   to get the non-animated value of an
   animated Animatable or UIElement.

*/

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;
using System.Windows.Input;

namespace Microsoft.Samples.Animation.TimingBehaviors
{


    public class GetAnimationBaseValueExample : Page {


        private RotateTransform animatedRotateTransform;
        public GetAnimationBaseValueExample()
        {

            WindowTitle = "GetAnimationBaseValue Example";
            StackPanel myPanel = new StackPanel();
            myPanel.Margin = new Thickness(20.0);    

            // Create a button.
            Button animatedButton = new Button();
            animatedButton.Content = "Click Me";
            animatedButton.Width = 100;
            animatedButton.Margin = new Thickness(100);

            // Create and animate a RotateTransform and
            // apply it to the button's RenderTransform
            // property.
            animatedRotateTransform = new RotateTransform();
            animatedRotateTransform.Angle = 45;
            DoubleAnimation angleAnimation = 
                new DoubleAnimation(0,360, TimeSpan.FromSeconds(5));
            angleAnimation.RepeatBehavior = RepeatBehavior.Forever;
            animatedRotateTransform.BeginAnimation(
                RotateTransform.AngleProperty, angleAnimation);           
            animatedButton.RenderTransform = animatedRotateTransform;
            animatedButton.RenderTransformOrigin = new Point(0.5,0.5);
            // Animate the button's width.
            DoubleAnimation widthAnimation = 
                new DoubleAnimation(120, 300, TimeSpan.FromSeconds(5));
            widthAnimation.RepeatBehavior = RepeatBehavior.Forever;
            widthAnimation.AutoReverse = true;
            animatedButton.BeginAnimation(Button.WidthProperty, widthAnimation);

            // Handle button clicks.
            animatedButton.Click += new RoutedEventHandler(animatedButton_Clicked);           

            // Add the button to the panel.
            myPanel.Children.Add(animatedButton);
            this.Content = myPanel;
        }

        // Display the base value for Button.Width and RotateTransform.Angle.
        private void animatedButton_Clicked(object sender, RoutedEventArgs e)
        {
            Button animatedButton = (Button)sender;
            MessageBox.Show("Button width base value: " + 
                animatedButton.GetAnimationBaseValue(Button.WidthProperty)
                + "\nRotateTransform base value: " +
                animatedRotateTransform.GetAnimationBaseValue(RotateTransform.AngleProperty));

        }

    }

}

참고 항목

개념

애니메이션 개요

참조

GetAnimationBaseValue

GetAnimationBaseValue

GetAnimationBaseValue