ProgressForm.xaml.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using InABox.Wpf;
  2. using System.Windows;
  3. using System.Windows.Media;
  4. using System.Windows.Threading;
  5. namespace InABox.WPF
  6. {
  7. /// <summary>
  8. /// Interaction logic for ProgressForm.xaml
  9. /// </summary>
  10. public partial class ProgressForm : ThemableWindow
  11. {
  12. private readonly ImageSource _image = null;
  13. private bool on = true;
  14. public ProgressForm()
  15. {
  16. InitializeComponent();
  17. Topmost = true;
  18. var timer = new DispatcherTimer(DispatcherPriority.Send)
  19. {
  20. Interval = new TimeSpan(0, 0, 0, 0, 500)
  21. };
  22. timer.Tick += (o, e) =>
  23. {
  24. on = !on;
  25. Progress.Background = new SolidColorBrush(on ? Colors.LightGreen : Colors.LightSalmon);
  26. };
  27. timer.IsEnabled = false;
  28. }
  29. public ImageSource DisplayImage
  30. {
  31. get => _image;
  32. set
  33. {
  34. Image.Width = value.Width;
  35. Image.Height = value.Height;
  36. Image.Background = new ImageBrush(value) { Stretch = Stretch.UniformToFill };
  37. }
  38. }
  39. //public void OpenWindow(String message)
  40. //{
  41. // if (Progress.Dispatcher.CheckAccess())
  42. // Update(message);
  43. // else
  44. // Progress.Dispatcher.BeginInvoke(new Action(() => { Update(message); }), DispatcherPriority.Send);
  45. //}
  46. //private delegate void UpdateDelegate(string message);
  47. //private void Update(String message)
  48. //{
  49. // Progress.Content = message;
  50. //}
  51. public void UpdateWindow(string message)
  52. {
  53. if (Progress.Dispatcher.CheckAccess())
  54. Progress.Content = message;
  55. else
  56. Progress.Dispatcher.Invoke(() => { Progress.Content = message; });
  57. //Progress.Dispatcher.BeginInvoke(new Action(() => { Update(message); }), DispatcherPriority.Send);
  58. }
  59. //private delegate void HideDelegate();
  60. public void CloseWindow()
  61. {
  62. if (Progress.Dispatcher.CheckAccess())
  63. Close();
  64. else
  65. Progress.Dispatcher.Invoke(() => { Close(); });
  66. //Progress.Dispatcher.BeginInvoke(new Action(() => { Close(); }), DispatcherPriority.Send);
  67. }
  68. public string GetMessage()
  69. {
  70. return Progress.Content as string;
  71. }
  72. private void Window_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
  73. {
  74. if(e.ChangedButton == System.Windows.Input.MouseButton.Left)
  75. {
  76. DragMove();
  77. }
  78. }
  79. }
  80. }