ProgressForm.xaml.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 _fader = new DoubleAnimation(1d, 0.3d, new Duration(TimeSpan.FromMilliseconds(3000))) { AutoReverse = true };
  16. public ProgressForm()
  17. {
  18. InitializeComponent();
  19. Topmost = true;
  20. Loaded += (sender, args) =>
  21. {
  22. _fader.Completed += (o, e) => Splash.BeginAnimation(Image.OpacityProperty, _fader);
  23. Splash.BeginAnimation(Image.OpacityProperty, _fader);
  24. };
  25. }
  26. public ImageSource? DisplayImage
  27. {
  28. get => Splash.Source;
  29. set => Splash.Source = value;
  30. }
  31. public void UpdateWindow(string message)
  32. {
  33. if (Progress.Dispatcher.CheckAccess())
  34. Progress.Content = message;
  35. else
  36. Progress.Dispatcher.Invoke(() => { Progress.Content = message; });
  37. }
  38. public void CloseWindow()
  39. {
  40. if (Progress.Dispatcher.CheckAccess())
  41. Close();
  42. else
  43. Progress.Dispatcher.Invoke(() => { Close(); });
  44. }
  45. public string GetMessage()
  46. {
  47. return Progress.Content as string;
  48. }
  49. private void Window_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
  50. {
  51. if(e.ChangedButton == System.Windows.Input.MouseButton.Left)
  52. {
  53. DragMove();
  54. }
  55. }
  56. }
  57. }