private void DisplayButtons(AltMessageBoxButton button) { Button_OK.Visibility = button.useOK ? System.Windows.Visibility.Visible : System.Windows.Visibility.Collapsed; Button_Yes.Visibility = button.useYes ? System.Windows.Visibility.Visible : System.Windows.Visibility.Collapsed; Button_No.Visibility = button.useNo ? System.Windows.Visibility.Visible : System.Windows.Visibility.Collapsed; Button_Cancel.Visibility = button.useCancel ? System.Windows.Visibility.Visible : System.Windows.Visibility.Collapsed; Button_Abort.Visibility = button.useAbort ? System.Windows.Visibility.Visible : System.Windows.Visibility.Collapsed; Button_Retry.Visibility = button.useRetry ? System.Windows.Visibility.Visible : System.Windows.Visibility.Collapsed; Button_YesToAll.Visibility = button.useYesToAll ? System.Windows.Visibility.Visible : System.Windows.Visibility.Collapsed; Button_NoToAll.Visibility = button.useNoToAll ? System.Windows.Visibility.Visible : System.Windows.Visibility.Collapsed; switch (button.Default) { case AltMessageBoxResult.None: break; case AltMessageBoxResult.OK: Button_OK.Focus(); break; case AltMessageBoxResult.Cancel: Button_Cancel.Focus(); break; case AltMessageBoxResult.Yes: Button_Yes.Focus(); break; case AltMessageBoxResult.No: Button_No.Focus(); break; case AltMessageBoxResult.Abort: Button_Abort.Focus(); break; case AltMessageBoxResult.Retry: Button_Retry.Focus(); break; case AltMessageBoxResult.YesToAll: Button_YesToAll.Focus(); break; case AltMessageBoxResult.NoToAll: Button_NoToAll.Focus(); break; default: break; } }
/// <summary> /// 创建对话框 /// </summary> /// <param name="title"> 标题</param> /// <param name="message">消息</param> /// <param name="lpCaption">类型 参考MB_开头常量</param> public MessageDialog(string title, string message, int lpCaption, int highlight = IDOK, int timer = 0) { InitializeComponent(); Text_Title.Text = title; Text_Message.Text = message; if (lpCaption == MB_OK) { Button_Ok.Tag = IDOK; Button_Ok.Content = "确认"; Button_Ok.Visibility = Visibility.Visible; } if (lpCaption == MB_OKCANCEL) { Button_Ok.Tag = IDOK; Button_Ok.Content = "确认"; Button_Ok.Visibility = Visibility.Visible; Button_No.Tag = IDCANCEL; Button_No.Content = "取消"; Button_No.Visibility = Visibility.Visible; } if (lpCaption == MB_YESNO) { Button_Ok.Tag = IDYES; Button_Ok.Content = "是"; Button_Ok.Visibility = Visibility.Visible; Button_No.Tag = IDNO; Button_No.Content = "否"; Button_No.Visibility = Visibility.Visible; } if (lpCaption == MB_YESNOCANCEL) { Button_Ok.Tag = IDYES; Button_Ok.Content = "是"; Button_Ok.Visibility = Visibility.Visible; Button_No.Tag = IDNO; Button_No.Content = "否"; Button_No.Visibility = Visibility.Visible; Button_Cancel.Tag = IDCANCEL; Button_Cancel.Content = "取消"; Button_Cancel.Visibility = Visibility.Visible; } if (highlight == IDOK || highlight == IDYES) { Button_Ok.SetResourceReference(StyleProperty, "AccentedSquareButtonStyle"); Button_Ok.Focus(); } if (highlight == IDCANCEL) { Button_Cancel.SetResourceReference(StyleProperty, "AccentedSquareButtonStyle"); Button_Cancel.Focus(); } if (highlight == IDNO) { Button_No.SetResourceReference(StyleProperty, "AccentedSquareButtonStyle"); Button_No.Focus(); } if (timer > 0) { Text_Timer.Text = timer.ToString(); Text_Timer.Tag = timer; Text_Timer.Visibility = Visibility.Visible; } }