我正在学习如何使用 C# 创建动画。因此,例如,如果我要为对象的边距设置动画,那么我将使用以下方法为其边距设置动画:
test(someObject, FrameworkElement.MarginProperty);
/// <summary>
/// animate margin of an object
/// </summary>
/// <param name="target">what object do you whant to animate?</param>
/// <param name="property">what property do you want to animate</param>
public void test(DependencyObject target, DependencyProperty property)
{
ThicknessAnimation animation = new ThicknessAnimation();
animation.To = new Thickness(0,0,0,0); // final value
//animation.From = new Thickness(50,50,50,50);
//make animation last 5 seconds
animation.BeginTime = TimeSpan.FromSeconds(0);
animation.Duration = TimeSpan.FromSeconds(5);
// set the ease function
BounceEase b = new BounceEase();
animation.EasingFunction = b;
//note that I would like to add an easeIn function
//start animating
Storyboard.SetTarget(animation, target); // what object will be animated?
Storyboard.SetTargetProperty(animation, new PropertyPath(property)); // what property will be animated
Storyboard sb = new Storyboard();
sb.Children.Add(animation);
sb.Begin();
}
请注意,我能够创建一个缓动功能。但是如果我想创建一个 EaseInOut 缓动函数怎么办。为了使用 EaseInOut 方法为对象设置动画,我必须在我的测试方法中添加什么。