DownloadAnimation.xaml.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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.Threading;
  16. namespace MediaBrowser.Installer.Code
  17. {
  18. /// <summary>
  19. /// Interaction logic for DownloadAnimation.xaml
  20. /// </summary>
  21. public partial class DownloadAnimation : UserControl
  22. {
  23. private int _i;
  24. private readonly double _startPos;
  25. private readonly DispatcherTimer _timer;
  26. public DownloadAnimation()
  27. {
  28. _i = 0;
  29. InitializeComponent();
  30. // Store start position of sliding canvas
  31. _startPos = Canvas.GetLeft(SlidingCanvas);
  32. // Create animation timer
  33. _timer = new DispatcherTimer {Interval = TimeSpan.FromMilliseconds(100)};
  34. _timer.Tick += TimerTick;
  35. }
  36. public void StartAnimation()
  37. {
  38. _timer.Start();
  39. }
  40. public void StopAnimation()
  41. {
  42. _timer.Stop();
  43. }
  44. private void TimerTick(object sender, EventArgs e)
  45. {
  46. _i++;
  47. if (_i < 16)
  48. {
  49. // Move SlidingCanvas containing the three colored dots 14 units to the right
  50. Canvas.SetLeft(SlidingCanvas, Canvas.GetLeft(SlidingCanvas) + 14);
  51. }
  52. else
  53. {
  54. // Move SlidingCanvas back to its starting position and reset counter
  55. _i = 0;
  56. Canvas.SetLeft(SlidingCanvas, _startPos);
  57. }
  58. }
  59. }
  60. }