星火微课系统客户端
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 5.0KB

4 lat temu
4 lat temu
4 lat temu
4 lat temu
4 lat temu
4 lat temu
4 lat temu
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. using System;
  2. using System.Threading;
  3. using System.Windows;
  4. using System.Windows.Controls;
  5. using System.Windows.Media.Imaging;
  6. using System.Windows.Threading;
  7. namespace XHWK.WKTool
  8. {
  9. /// <summary>
  10. /// CountdownWindow.xaml 的交互逻辑
  11. /// </summary>
  12. public partial class CountdownWindow : Window
  13. {
  14. /// <summary>
  15. /// 计时用
  16. /// </summary>
  17. private TimeSpan _timeSpan = new TimeSpan(0, 0, 0, 0, 0);
  18. DispatcherTimer timer = null;
  19. /// <summary>
  20. /// 状态
  21. /// </summary>
  22. private State _state = State.End;
  23. /// <summary>
  24. /// 计时器状态
  25. /// </summary>
  26. private enum State
  27. {
  28. Start,
  29. Pause,
  30. End
  31. }
  32. public CountdownWindow()
  33. {
  34. InitializeComponent();
  35. Initialize();
  36. }
  37. public void Initialize()
  38. {
  39. //Thread.Sleep(1200);
  40. //this.Hide();
  41. //MediaElement.Position
  42. //((MediaElement)((object)ImgGif)).Position= TimeSpan.Zero;
  43. //timer = new DispatcherTimer
  44. //{
  45. // Interval = TimeSpan.FromMilliseconds(2500)
  46. //};
  47. //timer.Tick += Timer_Tick;
  48. //timer.Start();
  49. if (timer == null)
  50. {
  51. timer = new DispatcherTimer();
  52. timer.Tick += OnTimer;
  53. timer.Interval = new TimeSpan(0, 0, 0, 1);
  54. timer.IsEnabled = true;
  55. timer.Start();
  56. }
  57. timer.Interval = new TimeSpan(0, 0, 0, 1);
  58. Stack();
  59. // 开启线程
  60. Thread tr = new Thread(new ThreadStart(Countdown))
  61. {
  62. IsBackground = true
  63. };
  64. tr.Start();
  65. }
  66. private void Countdown()
  67. {
  68. while (_timeSpan.Seconds <= 2)
  69. {
  70. if (_timeSpan.Seconds > 1)
  71. {
  72. Dispatcher.Invoke(
  73. DispatcherPriority.Normal,
  74. new Action(() => { imgLoding.Source = new BitmapImage(new Uri("pack://application:,,/Images/countdown_1.png")); })
  75. );
  76. }
  77. else if(_timeSpan.Seconds > 0)
  78. {
  79. Dispatcher.Invoke(
  80. DispatcherPriority.Normal,
  81. new Action(() => { imgLoding.Source = new BitmapImage(new Uri("pack://application:,,/Images/countdown_2.png")); })
  82. );
  83. }
  84. Thread.Sleep(888);
  85. }
  86. _state = State.End;
  87. Dispatcher.Invoke(
  88. DispatcherPriority.Normal,
  89. new Action(() => { this.Hide(); })
  90. );
  91. }
  92. /// <summary>
  93. /// 结束
  94. /// </summary>
  95. /// <param name="sender"></param>
  96. /// <param name="e"></param>
  97. private void End()
  98. {
  99. _state = State.End;
  100. }
  101. /// <summary>
  102. /// 时钟回调
  103. /// </summary>
  104. /// <param name="sender"></param>
  105. /// <param name="e"></param>
  106. private void OnTimer(object sender, EventArgs e)
  107. {
  108. switch (_state)
  109. {
  110. case State.Start:
  111. {
  112. _timeSpan += new TimeSpan(0, 0, 0, 1);
  113. }
  114. break;
  115. case State.Pause:
  116. {
  117. }
  118. break;
  119. case State.End:
  120. {
  121. _timeSpan = new TimeSpan();
  122. //_timeSpan = new TimeSpan(0, 23, 12, 45, 54);
  123. }
  124. break;
  125. }
  126. }
  127. /// <summary>
  128. /// 开始
  129. /// </summary>
  130. /// <param name="sender"></param>
  131. /// <param name="e"></param>
  132. private void Stack()
  133. {
  134. _state = State.Start;
  135. }
  136. private void Timer_Tick(object sender, EventArgs e)
  137. {
  138. this.Hide();
  139. timer.Stop();
  140. }
  141. /// <summary>
  142. /// 跳转页面
  143. /// </summary>
  144. /// <param name="sender"></param>
  145. /// <param name="e"></param>
  146. private void Window_ContentRendered(object sender, EventArgs e)
  147. {
  148. //Thread.Sleep(800);
  149. //imgLoding.Source = new BitmapImage(new Uri("pack://application:,,/Images/countdown_2.png"));
  150. //Thread.Sleep(800);
  151. //imgLoding.Source = new BitmapImage(new Uri("pack://application:,,/Images/countdown_1.png"));
  152. //Thread.Sleep(300);
  153. //this.Hide();
  154. //Initialize();
  155. }
  156. private void Image_MediaEnded(object sender, RoutedEventArgs e)
  157. {
  158. ((MediaElement)sender).Position = ((MediaElement)sender).Position.Add(TimeSpan.FromMilliseconds(10000));
  159. }
  160. }
  161. }