完成后如何删除动画

德拉格29

我想从目标属性中删除该动画,因为我无法在其动画之后设置该属性

因此,根据上述问题答案,我必须在完成动画后将其删除。但是怎么办呢

这是我的代码:

public class GridLengthAnimation : AnimationTimeline {

    static GridLengthAnimation() {
        FromProperty = DependencyProperty.Register("From", typeof(GridLength), typeof(GridLengthAnimation));
        ToProperty = DependencyProperty.Register("To", typeof(GridLength), typeof(GridLengthAnimation));
    }

    public override Type TargetPropertyType {
        get { return typeof(GridLength); }
    }

    protected override Freezable CreateInstanceCore() {
        return new GridLengthAnimation();
    }

    public ContentElement Target { get; set; }

    public static readonly DependencyProperty FromProperty;
    public GridLength From {
        get { return (GridLength) GetValue(FromProperty); }
        set { SetValue(FromProperty, value); }
    }

    public static readonly DependencyProperty ToProperty;
    public GridLength To {
        get { return (GridLength) GetValue(ToProperty); }
        set { SetValue(ToProperty, value); }
    }

    public void BeginAnimation() {
        Target.BeginAnimation(ColumnDefinition.WidthProperty, null);
        Target.BeginAnimation(ColumnDefinition.WidthProperty, this);
    }

    public IEasingFunction EasingFunction { get; set; } = new CubicEase() { EasingMode = EasingMode.EaseInOut };

    public override object GetCurrentValue(object defaultOriginValue, object defaultDestinationValue, AnimationClock animationClock) {
        double fromValue = ((GridLength) GetValue(FromProperty)).Value;
        double toValue = ((GridLength) GetValue(ToProperty)).Value;
        double newValue = 0;

        if ((fromValue > toValue)) {
            newValue = (1 - EasingFunction.Ease(animationClock.CurrentProgress.Value)) * (fromValue - toValue) + toValue;
            return new GridLength(newValue, GridUnitType.Star);
        } else {
            newValue = EasingFunction.Ease(animationClock.CurrentProgress.Value) * (toValue - fromValue) + fromValue;
            return new GridLength(newValue, GridUnitType.Star);
        }
    }
}

要开始动画,我在MainWindows.xaml.cs文件中这样做

GridLengthAnimation gridAnim = new GridLengthAnimation() {
    Name = "gridAnim",
    Target = mainGrid.ColumnDefinitions[1],
    Duration = new Duration(TimeSpan.FromMilliseconds(1000))
};

gridAnim.From = new GridLength(1, GridUnitType.Star);
gridAnim.To = new GridLength(0, GridUnitType.Star);

gridAnim.BeginAnimation();

动画制作完成后在哪里可以删除?

德拉格29

我发现我的解决方案在这里,在“从一个单独的属性中删除动画”的一部分。

我将此添加到我的GridLengthAnimation

public void BeginAnimation() {
    Completed += GridLengthAnimation_Completed;
    Target.BeginAnimation(ColumnDefinition.WidthProperty, null);
    Target.BeginAnimation(ColumnDefinition.WidthProperty, this);
}

private void GridLengthAnimation_Completed(object sender, EventArgs e) {
    //unlocks the property
    Target.BeginAnimation(ColumnDefinition.WidthProperty, null);

    //holds the value at the end
    ((ColumnDefinition) Target).Width = new GridLength(((GridLength) GetValue(ToProperty)).Value, GridUnitType.Star);
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

完成后如何从MPMoviePlayerController中删除动画

来自分类Dev

Velocity.js在动画完成后删除样式属性

来自分类Dev

动画完成后的TweenMax

来自分类Dev

完成后如何使动画重新工作?

来自分类常见问题

完成后如何防止CSS3动画重置?

来自分类Dev

如何等到动画完成后再调用函数

来自分类Dev

定向旋转动画完成后如何调用drawRect

来自分类Dev

gif动画完成后如何激活页面滚动

来自分类Dev

动画完成后隐藏动画文本

来自分类Dev

Java中线程完成后如何删除文件?

来自分类Dev

如何在作业完成后自动删除 Kubernetes 作业

来自分类Dev

AngularJS动画完成后运行代码

来自分类Dev

gif动画完成后触发javascript

来自分类Dev

动画完成后元素消失jquery

来自分类Dev

AngularJS动画完成后运行代码

来自分类Dev

完成后要重复动画吗?

来自分类Dev

动画完成后开始活动

来自分类Dev

动画完成后更改页面

来自分类Dev

动画完成后执行segue

来自分类Dev

GDscript:动画完成后射击子弹

来自分类Dev

动画完成后如何获取CSS3动画以保持其位置?

来自分类Dev

动画完成后如何使动画的最后一个关键帧“保持”

来自分类Dev

动画完成后,如何获取CSS3动画以保持其位置?

来自分类Dev

DownloadManager完成后删除烤面包

来自分类Dev

XmlHttpRequest完成后删除表行

来自分类Dev

执行动画,然后在动画完成后显示字段

来自分类Dev

动画完成后如何滚动到添加到NSTableView的行

来自分类Dev

动画完成后,如何恢复DataTrigger ExitActions中的初始值?

来自分类Dev

动画完成后如何在JQuery中执行某些操作