• WPF中动画


    动画命名空间:using System.Windows.Media.Animation;


                        Content="执行动画"
                x:Name="btn" 
                Width="100" 
                Height="40" 
                Click="btn_Click">
       

     

    1. using System;
    2. using System.Collections.Generic;
    3. using System.Linq;
    4. using System.Text;
    5. using System.Threading.Tasks;
    6. using System.Windows;
    7. using System.Windows.Controls;
    8. using System.Windows.Data;
    9. using System.Windows.Documents;
    10. using System.Windows.Input;
    11. using System.Windows.Media;
    12. using System.Windows.Media.Imaging;
    13. using System.Windows.Navigation;
    14. using System.Windows.Shapes;
    15. using System.Windows.Media.Animation;
    16. namespace WpfApp1
    17. {
    18. ///
    19. /// MainWindow.xaml 的交互逻辑
    20. ///
    21. public partial class MainWindow : Window
    22. {
    23. public MainWindow()
    24. {
    25. InitializeComponent();
    26. }
    27. private void btn_Click(object sender, RoutedEventArgs e)
    28. {
    29. //创建一个双精度的动画
    30. DoubleAnimation animation = new DoubleAnimation();
    31. animation.From = btn.Width;//动画的初始值
    32. animation.To = btn.Width - 30; //动画的结束值
    33. animation.Duration = TimeSpan.FromSeconds(2);//动画的持续时间
    34. animation.AutoReverse = true;//动画变化后恢复原状
    35. animation.RepeatBehavior = new RepeatBehavior(5);//new 执行次数 //RepeatBehavior.Forever;//一直重复执行 执行周期
    36. animation.Completed += animation_Completed;//动画完成后执行的事件
    37. btn.BeginAnimation(Button.WidthProperty, animation);
    38. }
    39. private void animation_Completed(object sender, EventArgs e)
    40. {
    41. btn.Content = "动画已完成";
    42. }
    43. }
    44. }

     

  • 相关阅读:
    STM32_OLED-打篮球.gif显示
    考研政治---马克思主义基本原理概论---绪论
    Solon 1.8.3 发布,云原生微服务开发框架
    深入浅出日志体系(logback最佳实践)
    把文件上传到Gitee的详细步骤
    html5 -- canvas使用(1)
    Dubbo+Zookeeper入门实例
    虚幻引擎中增强输入映射中鼠标输入无反应,怎么办?
    生产者消费者问题
    数据结构——线性表作业
  • 原文地址:https://blog.csdn.net/Canace_Xyxjjcaw/article/details/133669611