Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

73 rader
2.0 KiB

  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 BPA.UIControl
  15. {
  16. /// <summary>
  17. /// NotificationWindow.xaml 的交互逻辑
  18. /// </summary>
  19. public partial class NotificationWindow : Window
  20. {
  21. /// <summary>
  22. /// 单例消息窗体
  23. /// </summary>
  24. private static NotificationWindow notificationWindow = null;
  25. private NotificationWindow()
  26. {
  27. InitializeComponent();
  28. Application.Current.MainWindow.Closed += (sender, e) =>
  29. {
  30. Close();
  31. };
  32. }
  33. /// <summary>
  34. /// 获取实例
  35. /// </summary>
  36. /// <returns>MessageWindow 实例</returns>
  37. public static NotificationWindow GetInstance()
  38. {
  39. if (notificationWindow is null || !notificationWindow.IsLoaded)
  40. {
  41. notificationWindow = new NotificationWindow();
  42. }
  43. return notificationWindow;
  44. }
  45. /// <summary>
  46. /// 添加通知卡片
  47. /// </summary>
  48. /// <param name="notificationCard">通知卡片</param>
  49. internal void AddMessageCard(NotificationCard notificationCard)
  50. {
  51. notificationStackPanel.Children.Insert(0, notificationCard);
  52. }
  53. /// <summary>
  54. /// 移除通知卡片
  55. /// </summary>
  56. /// <param name="notificationCard">通知卡片</param>
  57. internal void RemoveMessageCard(NotificationCard notificationCard)
  58. {
  59. notificationStackPanel.Children.Remove(notificationCard);
  60. if (notificationStackPanel.Children.Count == 0)
  61. {
  62. Close();
  63. }
  64. }
  65. }
  66. }