LoadingWait.xaml.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Data;
  8. using System.Windows.Documents;
  9. using System.Windows.Input;
  10. using System.Windows.Media;
  11. using System.Windows.Media.Imaging;
  12. using System.Windows.Navigation;
  13. using System.Windows.Shapes;
  14. using System.Windows.Threading;
  15. namespace AGV_WPF
  16. {
  17. /// <summary>
  18. /// Interaction logic for LoadingWait.xaml
  19. /// </summary>
  20. public partial class LoadingWait : UserControl
  21. {
  22. #region Data
  23. private readonly DispatcherTimer animationTimer;
  24. #endregion
  25. int i = 0;
  26. #region Constructor
  27. public LoadingWait()
  28. {
  29. InitializeComponent();
  30. animationTimer = new DispatcherTimer(
  31. DispatcherPriority.ContextIdle, Dispatcher);
  32. animationTimer.Interval = new TimeSpan(0, 0, 0, 0, 90);
  33. }
  34. #endregion
  35. #region Private Methods
  36. private void Start()
  37. {
  38. animationTimer.Tick += HandleAnimationTick;
  39. animationTimer.Start();
  40. }
  41. private void Stop()
  42. {
  43. animationTimer.Stop();
  44. animationTimer.Tick -= HandleAnimationTick;
  45. }
  46. private void HandleAnimationTick(object sender, EventArgs e)
  47. {
  48. SpinnerRotate.Angle = (SpinnerRotate.Angle + 36) % 360;
  49. i++;
  50. if (i>60)//60*90=5400ms
  51. {
  52. Application.Current.Shutdown();
  53. }
  54. }
  55. private void HandleLoaded(object sender, RoutedEventArgs e)
  56. {
  57. const double offset = Math.PI;
  58. const double step = Math.PI * 2 / 10.0;
  59. SetPosition(C0, offset, 0.0, step);
  60. SetPosition(C1, offset, 1.0, step);
  61. SetPosition(C2, offset, 2.0, step);
  62. SetPosition(C3, offset, 3.0, step);
  63. SetPosition(C4, offset, 4.0, step);
  64. SetPosition(C5, offset, 5.0, step);
  65. SetPosition(C6, offset, 6.0, step);
  66. SetPosition(C7, offset, 7.0, step);
  67. SetPosition(C8, offset, 8.0, step);
  68. }
  69. private void SetPosition(Ellipse ellipse, double offset,
  70. double posOffSet, double step)
  71. {
  72. ellipse.SetValue(Canvas.LeftProperty, 50.0
  73. + Math.Sin(offset + posOffSet * step) * 50.0);
  74. ellipse.SetValue(Canvas.TopProperty, 50
  75. + Math.Cos(offset + posOffSet * step) * 50.0);
  76. }
  77. private void HandleUnloaded(object sender, RoutedEventArgs e)
  78. {
  79. Stop();
  80. }
  81. private void HandleVisibleChanged(object sender,
  82. DependencyPropertyChangedEventArgs e)
  83. {
  84. bool isVisible = (bool)e.NewValue;
  85. if (isVisible)
  86. Start();
  87. else
  88. Stop();
  89. }
  90. #endregion
  91. }
  92. }