动画 Animation
1 | using System.Windows.Media.Animation; |
1 2 3 4 5 | <Grid> <StackPanel> <Button x:Name= "btn" Content= "执行动画" Width= "100" Height= "40" Click= "Button_Click" /> </StackPanel> </Grid> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | private void Button_Click( object sender, RoutedEventArgs e) { //创建一个双精度的动画 DoubleAnimation animation = new DoubleAnimation(); animation.By = -30; //设置范围,在原来的基础上减30 //animation.From = btn.Width;//动画开始值 //animation.To = btn.Width - 30;//动画结束值 animation.Duration = TimeSpan.FromSeconds(3); //动画的持续时间 animation.AutoReverse = true ; //执行完动画之后,恢复到原始状态 //animation.RepeatBehavior = RepeatBehavior.Forever;//动画一直持续执行 //animation.RepeatBehavior = new RepeatBehavior(3);//动画执行3次 animation.Completed += Animation_Completed; //在当前按钮上执行该动画 btn.BeginAnimation(Button.WidthProperty, animation); } private void Animation_Completed( object ? sender, EventArgs e) { btn.Content = "动画已完成" ; } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义