private void BModalDialog_Click(object sender, RoutedEventArgs e) { const string message = "My message sample"; var longText = $"Bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla.\r" + "Bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla.\r" + "Bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla."; const ModalDialogButtons buttons = ModalDialogButtons.YesNoCancel; const ModalDialogIcon icon = ModalDialogIcon.Information; Mdlg.Show( $"Modal Dialog Result: \r\"{Mdlg.Show(message, buttons, icon)}\"" // $"Modal Dialog Result: \r\"{Mdlg.Show(longText, buttons, icon)}\"" ); }
private ModalDialogResult PrivateShow(UIElement parentElement, string message, ModalDialogButtons buttons, ModalDialogIcon icon) { var parentWindow = Window.GetWindow(Parent); parentWindow?.Activate(); if ((parentWindow != null) && (parentWindow.WindowState == WindowState.Minimized)) { parentWindow.WindowState = WindowState.Normal; } Keyboard.Focus(parentWindow); if (parentElement == null) { throw new ArgumentNullException(nameof(parentElement)); } Window.GetWindow(this)?.Activate(); if (parentElement == null) { throw new ArgumentNullException(nameof(parentElement)); } _focusedControl = Keyboard.FocusedElement; Message = message; _buttons = buttons; Icon = icon; switch (_buttons) { case ModalDialogButtons.Ok: SetButtonValues(OkButton, true, true, true, OkTitle); SetButtonValues(CancelButton, false); SetButtonValues(Cancel2Button, false); break; case ModalDialogButtons.OkCancel: SetButtonValues(OkButton, true, true, false, OkTitle); SetButtonValues(CancelButton, true, false, true, CancelTitle); SetButtonValues(Cancel2Button, false); break; case ModalDialogButtons.YesNo: SetButtonValues(OkButton, true, true, false, YesTitle); SetButtonValues(CancelButton, true, false, true, NoTitle); SetButtonValues(Cancel2Button, false); break; case ModalDialogButtons.YesNoCancel: SetButtonValues(OkButton, true, false, false, YesTitle); SetButtonValues(CancelButton, true, false, false, NoTitle); SetButtonValues(Cancel2Button, true, true, true, CancelTitle); break; default: throw new ArgumentOutOfRangeException(nameof(buttons)); } Visibility = Visibility.Visible; ParentElement.IsEnabled = false; _hideRequest = false; while (!_hideRequest) { if (Dispatcher.HasShutdownStarted || Dispatcher.HasShutdownFinished) { break; } Dispatcher.Invoke(DispatcherPriority.Background, new ThreadStart(delegate { })); Thread.Sleep(20); } return(_result); }
/// <summary> /// Выводит сообщение /// </summary> /// <param name="message">Текст сообщения</param> /// <param name="buttons">Набор кнопок сообщения</param> /// <param name="icon">Иконка сообщения</param> /// <returns>Результат вывода сообщения</returns> public ModalDialogResult Show(string message, ModalDialogButtons buttons, ModalDialogIcon icon) { return(PrivateShow(ParentElement, message, buttons, icon)); }