создать функцию плавности программно C#

Я учусь создавать анимацию с помощью 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.


person Tono Nam    schedule 08.08.2011    source источник


Ответы (1)


Я думаю, что наконец-то заработал мой метод, чтобы анимировать поля объекта.

MyStoryboards.Animations a = new MyStoryboards.Animations();

// set the ease function
BounceEase b = new BounceEase();
b.Bounces = 5;
b.Bounciness = 1;
b.EasingMode = EasingMode.EaseIn;

a.animThickness(tv, FrameworkElement.MarginProperty, tv.Margin, new Thickness(), TimeSpan.FromSeconds(0), TimeSpan.FromSeconds(5), b);

...

...

public void animThickness(DependencyObject target, DependencyProperty property, Thickness from, Thickness to, TimeSpan beginTime, TimeSpan duration , IEasingFunction e)
{
    ThicknessAnimation animation = new ThicknessAnimation();
    animation.To = to;   // final value

    animation.From = from;

    animation.BeginTime = beginTime;
    animation.Duration = duration;

    animation.EasingFunction = e;

    //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();
}
person Tono Nam    schedule 08.08.2011