ResultDialog.xaml.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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.Shapes;
  14. namespace ST_CUBE_MES
  15. {
  16. /// <summary>
  17. /// Window1.xaml 的互動邏輯
  18. /// </summary>
  19. public partial class ResultDialog : Window
  20. {
  21. public ResultDialog()
  22. {
  23. InitializeComponent();
  24. KeyDown += ResultDialog_KeyDown;
  25. MouseDown += ResultDialog_MouseDown;
  26. }
  27. public event EventHandler OnAnyInput;
  28. public bool IsSuccess { get; private set; }
  29. private delegate void GenericDelegate();
  30. private void ResultDialog_KeyDown(object sender, KeyEventArgs e)
  31. {
  32. OnAnyInput?.Invoke(this, e);
  33. }
  34. private void ResultDialog_MouseDown(object sender, MouseButtonEventArgs e)
  35. {
  36. OnAnyInput?.Invoke(this, e);
  37. }
  38. public void ShowResult(bool isSuccess)
  39. {
  40. GenericDelegate ShowResultAct = () => {
  41. if (isSuccess)
  42. {
  43. uxBg.Background = Brushes.Lime;
  44. uxResultText.Content = "PASS";
  45. }
  46. if (!isSuccess)
  47. {
  48. uxBg.Background = Brushes.Red;
  49. uxResultText.Content = "FAIL";
  50. }
  51. IsSuccess = isSuccess;
  52. this.ShowDialog();
  53. };
  54. this.Dispatcher.BeginInvoke(ShowResultAct);
  55. }
  56. }
  57. }