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;
标签:动画,slideAnimation,Thickness,ThicknessAnimation,滑入,new,WPF,Margin From: https://www.cnblogs.com/xuzhongjie/p/16805232.html