终端一体化运控平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

111 lines
2.9 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 BPASmart.UserManagement
  15. {
  16. /// <summary>
  17. /// MessageBox.xaml 的交互逻辑
  18. /// </summary>
  19. public class MessageResult
  20. {
  21. /// <summary>
  22. /// 结果,Yes为true,No为false
  23. /// </summary>
  24. public bool IsYes { get; set; }
  25. }
  26. public class MessageBoxEventArgs : EventArgs
  27. {
  28. /// <summary>
  29. /// 结果,Yes为true,No为false
  30. /// </summary>
  31. public MessageResult Result { get; set; }
  32. }
  33. /// <summary>
  34. /// MessageBox.xaml 的交互逻辑
  35. /// </summary>
  36. public partial class MessageBox : Window
  37. {
  38. public event EventHandler<MessageBoxEventArgs> Result;
  39. public string Context
  40. {
  41. get { return TB_Context.Text; }
  42. set { TB_Context.Text = value; }
  43. }
  44. bool _isLegal = false;
  45. public MessageBox()
  46. {
  47. InitializeComponent();
  48. }
  49. public static void Show(string context, EventHandler<MessageBoxEventArgs> result)
  50. {
  51. var mb = new MessageBox();
  52. mb.Context = context;
  53. mb.Result += result;
  54. mb.Show();
  55. }
  56. public static void Show(string context)
  57. {
  58. var mb = new MessageBox();
  59. mb.Context = context;
  60. mb.Show();
  61. }
  62. public static MessageResult ShowDialog(string context)
  63. {
  64. var mb = new MessageBox();
  65. mb.Context = context;
  66. MessageResult r = null;
  67. mb.Result += (s, e) =>
  68. {
  69. r = e.Result;
  70. };
  71. mb.ShowDialog();
  72. return r;
  73. }
  74. private void No_Button_Click(object sender, RoutedEventArgs e)
  75. {
  76. _isLegal = true;
  77. Close();
  78. Result?.Invoke(this, new MessageBoxEventArgs() { Result = new MessageResult() { IsYes = false } });
  79. }
  80. private void Yes_Button_Click(object sender, RoutedEventArgs e)
  81. {
  82. _isLegal = true;
  83. Close();
  84. Result?.Invoke(this, new MessageBoxEventArgs() { Result = new MessageResult() { IsYes = true } });
  85. }
  86. private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
  87. {
  88. e.Cancel = !_isLegal;
  89. }
  90. private void Border_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  91. {
  92. this.DragMove();
  93. }
  94. private void Window_KeyDown(object sender, KeyEventArgs e)
  95. {
  96. if(e.Key == Key.Enter)
  97. {
  98. Close();
  99. }
  100. }
  101. }
  102. }