123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- using System;
- using System.Threading;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Media.Imaging;
- using System.Windows.Threading;
-
- namespace XHWK.WKTool
- {
- /// <summary>
- /// CountdownWindow.xaml 的交互逻辑
- /// </summary>
- public partial class CountdownWindow : Window
- {
- /// <summary>
- /// 计时用
- /// </summary>
- private TimeSpan _timeSpan = new TimeSpan(0, 0, 0, 0, 0);
- DispatcherTimer timer = null;
- /// <summary>
- /// 状态
- /// </summary>
- private State _state = State.End;
- /// <summary>
- /// 计时器状态
- /// </summary>
- private enum State
- {
- Start,
- Pause,
- End
- }
- public CountdownWindow()
- {
- InitializeComponent();
- Initialize();
- }
- public void Initialize()
- {
- //Thread.Sleep(1200);
- //this.Hide();
- //MediaElement.Position
- //((MediaElement)((object)ImgGif)).Position= TimeSpan.Zero;
- //timer = new DispatcherTimer
- //{
- // Interval = TimeSpan.FromMilliseconds(2500)
- //};
- //timer.Tick += Timer_Tick;
- //timer.Start();
-
-
-
- if (timer == null)
- {
- timer = new DispatcherTimer();
- timer.Tick += OnTimer;
- timer.Interval = new TimeSpan(0, 0, 0, 1);
- timer.IsEnabled = true;
- timer.Start();
- }
- timer.Interval = new TimeSpan(0, 0, 0, 1);
- Stack();
-
-
- // 开启线程
- Thread tr = new Thread(new ThreadStart(Countdown))
- {
- IsBackground = true
- };
- tr.Start();
-
- }
- private void Countdown()
- {
- while (_timeSpan.Seconds <= 2)
- {
-
- if (_timeSpan.Seconds > 1)
- {
- Dispatcher.Invoke(
- DispatcherPriority.Normal,
- new Action(() => { imgLoding.Source = new BitmapImage(new Uri("pack://application:,,/Images/countdown_1.png")); })
- );
-
- }
- else if(_timeSpan.Seconds > 0)
- {
- Dispatcher.Invoke(
- DispatcherPriority.Normal,
- new Action(() => { imgLoding.Source = new BitmapImage(new Uri("pack://application:,,/Images/countdown_2.png")); })
- );
-
- }
- Thread.Sleep(888);
- }
-
-
- _state = State.End;
- Dispatcher.Invoke(
- DispatcherPriority.Normal,
- new Action(() => { this.Hide(); })
- );
-
- }
- /// <summary>
- /// 结束
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void End()
- {
- _state = State.End;
- }
-
- /// <summary>
- /// 时钟回调
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void OnTimer(object sender, EventArgs e)
- {
- switch (_state)
- {
- case State.Start:
- {
- _timeSpan += new TimeSpan(0, 0, 0, 1);
- }
- break;
-
- case State.Pause:
- {
- }
- break;
-
- case State.End:
- {
- _timeSpan = new TimeSpan();
- //_timeSpan = new TimeSpan(0, 23, 12, 45, 54);
- }
- break;
- }
-
-
- }
- /// <summary>
- /// 开始
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void Stack()
- {
- _state = State.Start;
- }
- private void Timer_Tick(object sender, EventArgs e)
- {
- this.Hide();
- timer.Stop();
- }
-
- /// <summary>
- /// 跳转页面
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void Window_ContentRendered(object sender, EventArgs e)
- {
- //Thread.Sleep(800);
- //imgLoding.Source = new BitmapImage(new Uri("pack://application:,,/Images/countdown_2.png"));
- //Thread.Sleep(800);
- //imgLoding.Source = new BitmapImage(new Uri("pack://application:,,/Images/countdown_1.png"));
- //Thread.Sleep(300);
- //this.Hide();
-
- //Initialize();
- }
-
- private void Image_MediaEnded(object sender, RoutedEventArgs e)
- {
- ((MediaElement)sender).Position = ((MediaElement)sender).Position.Add(TimeSpan.FromMilliseconds(10000));
- }
- }
- }
|