WindowHelper.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using Hardcodet.Wpf.TaskbarNotification;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using static System.Windows.Forms.VisualStyles.VisualStyleElement;
  9. namespace EEMSCenterUI.Helper;
  10. internal class WindowHelper
  11. {
  12. private static bool _isShow = true;
  13. public static bool ShowWindow()
  14. {
  15. Application.Current.MainWindow.Show();
  16. _isShow = true;
  17. return true;
  18. }
  19. public static void AutoHideShow()
  20. {
  21. _ = _isShow switch
  22. {
  23. true => HideWindow(),
  24. false => ShowWindow(),
  25. };
  26. }
  27. public static bool HideWindow()
  28. {
  29. App.ShowBalloonTip("EEMS Server", "服务正在后台运行...", BalloonIcon.Info);
  30. Application.Current.MainWindow.Hide();
  31. _isShow = false;
  32. return true;
  33. }
  34. public static bool ExitWindow()
  35. {
  36. MessageBoxResult result = MessageBox.Show(Application.Current.MainWindow, "确认退出 EEMS 服务?", "退出提示", MessageBoxButton.YesNo, MessageBoxImage.Question);
  37. switch (result)
  38. {
  39. case MessageBoxResult.Yes:
  40. App.Current.Shutdown();
  41. break;
  42. case MessageBoxResult.None:
  43. case MessageBoxResult.OK:
  44. case MessageBoxResult.Cancel:
  45. case MessageBoxResult.No:
  46. default:
  47. break;
  48. }
  49. return true;
  50. }
  51. }