|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Shapes;
-
- namespace BPASmart.UserManagement
- {
- /// <summary>
- /// MessageBox.xaml 的交互逻辑
- /// </summary>
-
- public class MessageResult
- {
- /// <summary>
- /// 结果,Yes为true,No为false
- /// </summary>
- public bool IsYes { get; set; }
- }
- public class MessageBoxEventArgs : EventArgs
- {
- /// <summary>
- /// 结果,Yes为true,No为false
- /// </summary>
- public MessageResult Result { get; set; }
- }
- /// <summary>
- /// MessageBox.xaml 的交互逻辑
- /// </summary>
- public partial class MessageBox : Window
- {
- public event EventHandler<MessageBoxEventArgs> Result;
-
- public string Context
- {
- get { return TB_Context.Text; }
- set { TB_Context.Text = value; }
- }
- bool _isLegal = false;
- public MessageBox()
- {
- InitializeComponent();
- }
- public static void Show(string context, EventHandler<MessageBoxEventArgs> result)
- {
- var mb = new MessageBox();
- mb.Context = context;
- mb.Result += result;
- mb.Show();
- }
- public static void Show(string context)
- {
- var mb = new MessageBox();
- mb.Context = context;
- mb.Show();
- }
- public static MessageResult ShowDialog(string context)
- {
- var mb = new MessageBox();
- mb.Context = context;
- MessageResult r = null;
- mb.Result += (s, e) =>
- {
- r = e.Result;
- };
- mb.ShowDialog();
- return r;
- }
- private void No_Button_Click(object sender, RoutedEventArgs e)
- {
- _isLegal = true;
- Close();
- Result?.Invoke(this, new MessageBoxEventArgs() { Result = new MessageResult() { IsYes = false } });
- }
- private void Yes_Button_Click(object sender, RoutedEventArgs e)
- {
- _isLegal = true;
- Close();
- Result?.Invoke(this, new MessageBoxEventArgs() { Result = new MessageResult() { IsYes = true } });
- }
- private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
- {
- e.Cancel = !_isLegal;
- }
-
- private void Border_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
- {
- this.DragMove();
- }
-
- private void Window_KeyDown(object sender, KeyEventArgs e)
- {
- if(e.Key == Key.Enter)
- {
- Close();
- }
- }
- }
- }
-
-
-
|