NotificationDialog.xaml.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Data;
  8. using System.Windows.Documents;
  9. using System.Windows.Input;
  10. using System.Windows.Media;
  11. using System.Windows.Media.Imaging;
  12. using System.Windows.Navigation;
  13. using System.Windows.Shapes;
  14. namespace Aitex.Core.UI.Dialog
  15. {
  16. /// <summary>
  17. /// Interaction logic for NotificationDialog.xaml
  18. /// </summary>
  19. public partial class NotificationDialog : Window
  20. {
  21. public NotificationDialog()
  22. {
  23. InitializeComponent();
  24. Closing += new System.ComponentModel.CancelEventHandler(NotificationDialog_Closing);
  25. _tm.Elapsed += new System.Timers.ElapsedEventHandler(_tm_Elapsed);
  26. _tm.Start();
  27. BannerColor = Brushes.DodgerBlue;
  28. }
  29. private TimeSpan _autoCloseTime = new TimeSpan(0, 1, 0);
  30. void NotificationDialog_Closing(object sender, System.ComponentModel.CancelEventArgs e)
  31. {
  32. _tm.Stop();
  33. }
  34. DateTime _startTime = DateTime.Now;
  35. System.Timers.Timer _tm = new System.Timers.Timer(500);
  36. void _tm_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
  37. {
  38. if (DateTime.Now - _startTime > _autoCloseTime)
  39. {
  40. //延迟1min后,自动关闭提示对话框
  41. Dispatcher.Invoke(new Action(() =>
  42. {
  43. Close();
  44. }));
  45. }
  46. else
  47. {
  48. //显示对话框弹出显示至今的时间
  49. labelElapsedTime.Dispatcher.BeginInvoke(new Action(() =>
  50. {
  51. labelElapsedTime.Content = (_startTime + new TimeSpan(0, 1, 0) - DateTime.Now).ToString(@"hh\:mm\:ss");
  52. }));
  53. }
  54. }
  55. /// <summary>
  56. /// close current window
  57. /// </summary>
  58. /// <param name="sender"></param>
  59. /// <param name="e"></param>
  60. private void buttonOK_Click(object sender, RoutedEventArgs e)
  61. {
  62. _tm.Stop();
  63. Close();
  64. }
  65. /// <summary>
  66. /// Message title
  67. /// </summary>
  68. public string MessageTitle
  69. {
  70. get
  71. {
  72. return _msgTitle.Text;
  73. }
  74. set
  75. {
  76. _msgTitle.Text = value;
  77. }
  78. }
  79. /// <summary>
  80. /// Message content
  81. /// </summary>
  82. public string MessageContent
  83. {
  84. get
  85. {
  86. return _msgContent.Text;
  87. }
  88. set
  89. {
  90. _msgContent.Text = value;
  91. }
  92. }
  93. /// <summary>
  94. /// Banner color
  95. /// </summary>
  96. public Brush BannerColor
  97. {
  98. get
  99. {
  100. return topGrid.Background;
  101. }
  102. set
  103. {
  104. topGrid.Background = value;
  105. }
  106. }
  107. }
  108. }