WPF 创建左侧滑入动画

    var sb = new Storyboard();              // 动画板
    var slideAnimation = new ThicknessAnimation()       // 由于控制的是Margin,属于Thickness类型,所以创建ThicknessAnimation动画
    {
        Duration = new Duration(TimeSpan.FromSeconds(SlideSeconds)),    // 动画持续的时间
        From = new Thickness(this.WindowWidth, 0, 0, 0),                // 动画起始位置,Margin = new Thickness(this.WindowWidth,0,0,0)
        To = new Thickness(0),                                          // 动画结束位置,Margin = new Thickness(0)
        DecelerationRatio = 0.9f                                        // 动画停止前减速效果
    };
    Storyboard.SetTargetProperty(slideAnimation, new PropertyPath("Margin"));   // 绑定Margin
    sb.Children.Add(slideAnimation);    // 动画板添加ThicknessAnimation动画
    sb.Begin(this);                     // 动画关联到指定窗体
    this.Visibility = Visibility.Visible;   // 显示窗体
    await Task.Delay((int)(this.SlideSeconds * 1000));
    break;

 

posted on 2022-10-19 09:59  xzj19870125  阅读(136)  评论(0编辑  收藏  举报

导航