星火微课系统客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CountdownWindow.xaml.cs 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. using System;
  2. using System.Windows;
  3. using System.Windows.Media.Imaging;
  4. using System.Windows.Threading;
  5. namespace XHWK.WKTool
  6. {
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Threading.Tasks;
  10. /// <summary>
  11. /// 录屏等待 CountdownWindow.xaml 的交互逻辑
  12. /// </summary>
  13. public partial class CountdownWindow
  14. {
  15. private readonly List<BitmapImage> _images = new List<BitmapImage>();
  16. public CountdownWindow()
  17. {
  18. InitializeComponent();
  19. foreach (var imgName in _imgNames)
  20. {
  21. _images.Add(new BitmapImage(new Uri("pack://application:,,/Images/" + imgName)));
  22. }
  23. }
  24. /// <summary>
  25. /// 计时器
  26. /// </summary>
  27. private int _imgNum = 22;
  28. public void InitAndShow(bool showlblShortcut = false, int changeTime = 3000)
  29. {
  30. imgLoding.Source = _images.Last();
  31. Init(showlblShortcut, changeTime);
  32. Show();
  33. }
  34. private System.Timers.Timer _timer;
  35. private async void Init(bool showlblShortcut, int changeTime)
  36. {
  37. if (showlblShortcut)
  38. {
  39. lblShortcut.Visibility = Visibility.Visible;
  40. borShortcut.Visibility = Visibility.Visible;
  41. }
  42. else
  43. {
  44. lblShortcut.Visibility = Visibility.Hidden;
  45. borShortcut.Visibility = Visibility.Hidden;
  46. }
  47. _imgNum = 22;
  48. _timer = new System.Timers.Timer();
  49. _timer.Enabled = true;
  50. _timer.Interval = 1.0 * changeTime / 22;
  51. _timer.Elapsed += Timer_Elapsed;
  52. _timer.Disposed += _timer_Disposed;
  53. _timer.Start();
  54. await Task.Delay(300);
  55. }
  56. private void _timer_Disposed(object sender, EventArgs e)
  57. {
  58. Dispatcher.Invoke
  59. (
  60. async () =>
  61. {
  62. // 执行操作
  63. imgLoding.Source = null;
  64. await Task.Delay(300);
  65. Hide();
  66. },
  67. DispatcherPriority.Send
  68. );
  69. }
  70. private void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
  71. {
  72. if (_imgNum >= 0)
  73. {
  74. Dispatcher.Invoke
  75. (
  76. () =>
  77. {
  78. // 执行操作
  79. imgLoding.Source = _images[_imgNum];
  80. },
  81. DispatcherPriority.Send
  82. );
  83. _imgNum--;
  84. }
  85. else
  86. {
  87. _timer.Stop();
  88. _timer.Dispose();
  89. }
  90. }
  91. readonly string[] _imgNames =
  92. {
  93. "countdown1_7.png",
  94. "countdown1_6.png",
  95. "countdown1_5.png",
  96. "countdown1_4.png",
  97. "countdown1_3.png",
  98. "countdown1_2.png",
  99. "countdown1_1.png",
  100. "countdown2_7.png",
  101. "countdown2_6.png",
  102. "countdown2_5.png",
  103. "countdown2_4.png",
  104. "countdown2_3.png",
  105. "countdown2_2.png",
  106. "countdown2_1.png",
  107. "countdown3_8.png",
  108. "countdown3_7.png",
  109. "countdown3_6.png",
  110. "countdown3_5.png",
  111. "countdown3_4.png",
  112. "countdown3_3.png",
  113. "countdown3_2.png",
  114. "countdown3_1.png",
  115. "countdown3_1.png",
  116. };
  117. }
  118. }