Пример #1
0
 public MsgBox()
 {
     InitializeComponent();
     Title = "";
     Text  = "";
     Back  = Visibility.Visible;
     SetButtons(null);
     btns = new Button[] { Btn1, Btn2, Btn3 };
     for (int i = 0; i < btns.Length; ++i)
     {
         var package_i = i;
         btns[i].Click += (s, e) => {
             if (Visibility == Visibility.Visible)
             {
                 var args = new MsgBoxEventArgs(package_i, btns[package_i].Content.ToString());
                 MsgBoxTrigger?.Invoke(this, args);
                 foreach (var func in OnceEvent)
                 {
                     func?.Invoke(this, args);
                 }
                 OnceEvent.Clear();
                 Dispatcher.Invoke(() => Visibility = Visibility.Collapsed);//注意线程同步的问题。
             }
         };
     }
 }
Пример #2
0
 public void Show(MsgBoxEvent func = null, string title = "", string contenttext = "", Visibility?back = null, string[] buttonname = null)
 {
     Dispatcher.Invoke(() => {
         if (title != null)
         {
             Title = title;
         }
         if (contenttext != null)
         {
             Text = contenttext;
         }
         if (back.HasValue)
         {
             Back = back.Value;
         }
         if (buttonname != null)
         {
             SetButtons(buttonname);
         }
         Visibility = Visibility.Visible;
     });
     OnceEvent.Add(func);
 }
Пример #3
0
 public MsgBox AddOnceEvent(MsgBoxEvent func)
 {
     OnceEvent.Add(func);
     return(this);
 }