ProgressForm.xaml.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using InABox.Wpf;
  2. using System;
  3. using System.Windows;
  4. using System.Windows.Controls;
  5. using System.Windows.Media;
  6. using System.Windows.Media.Animation;
  7. namespace InABox.WPF
  8. {
  9. /// <summary>
  10. /// Interaction logic for ProgressForm.xaml
  11. /// </summary>
  12. public partial class ProgressForm : ThemableWindow
  13. {
  14. private ImageSource? _image = null;
  15. private DoubleAnimation _fadein = new DoubleAnimation(1d, new Duration(TimeSpan.FromSeconds(3)));
  16. private DoubleAnimation _fadeout = new DoubleAnimation(0.2d, new Duration(TimeSpan.FromSeconds(3)));
  17. public ProgressForm()
  18. {
  19. InitializeComponent();
  20. Topmost = true;
  21. Loaded += (sender, args) =>
  22. {
  23. _fadeout.Completed += (o, e) => Splash.BeginAnimation(Image.OpacityProperty, _fadein);
  24. _fadein.Completed += (o, e) => Splash.BeginAnimation(Image.OpacityProperty, _fadeout);
  25. Splash.BeginAnimation(Image.OpacityProperty, _fadeout);
  26. };
  27. }
  28. public ImageSource? DisplayImage
  29. {
  30. get => Splash.Source;
  31. set => Splash.Source = value;
  32. }
  33. public void UpdateWindow(string message)
  34. {
  35. if (Progress.Dispatcher.CheckAccess())
  36. Progress.Content = message;
  37. else
  38. Progress.Dispatcher.Invoke(() => { Progress.Content = message; });
  39. }
  40. public void CloseWindow()
  41. {
  42. if (Progress.Dispatcher.CheckAccess())
  43. Close();
  44. else
  45. Progress.Dispatcher.Invoke(() => { Close(); });
  46. }
  47. public string GetMessage()
  48. {
  49. return Progress.Content as string;
  50. }
  51. private void Window_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
  52. {
  53. if(e.ChangedButton == System.Windows.Input.MouseButton.Left)
  54. {
  55. DragMove();
  56. }
  57. }
  58. }
  59. }