/// <summary> /// Displays the dialog model with the control embedded. /// </summary> /// <param name="title">The title to be displayed.</param> /// <param name="buttons">The buttons to be displayed.</param> /// <param name="defaultButton">The default button.</param> /// <param name="content">The content control to be embedded.</param> /// <returns>Identifies the dialog button pressed to exit the dialog.</returns> public ResultMessage DisplayModal(string title, MessageButton buttons, DefaultMessageButton defaultButton, Control content) { var viewModel = new StandardButtonDialogFrameVm(title, buttons, defaultButton); this.DataContext = viewModel; this.controlContainer.Children.Add(content); this.ShowDialog(); return(viewModel.Result); }
/// <summary> /// Initializes a new instance of the <see cref="MessageBoxVm"/> class. /// </summary> /// <param name="title">The title.</param> /// <param name="message">The message.</param> /// <param name="messageButton">The message button.</param> /// <param name="messageType">Type of the message.</param> /// <param name="defaultMessageButton">The default message button.</param> public MessageBoxVm(string title, string message, MessageButton messageButton, MessageType messageType, DefaultMessageButton defaultMessageButton) { this.defaultMessageButton = defaultMessageButton; this.resultMessage = EnumConverter.DefaultMessageButtonToResultMessage(this.defaultMessageButton); this.Title = title; this.Message = message; this.MessageType = messageType; this.MessageButton = messageButton; this.commandOk = new DelegateCommand(this.ButtonOkPressed); this.commandCancel = new DelegateCommand(this.ButtonCancelPressed); this.commandIgnore = new DelegateCommand(this.ButtonIgnorePressed); this.commandNo = new DelegateCommand(this.ButtonNoPressed); this.commandRetry = new DelegateCommand(this.ButtonRetryPressed); this.commandAbort = new DelegateCommand(this.ButtonAbortPressed); this.commandYes = new DelegateCommand(this.ButtonYesPressed); }
/// <summary> /// Converts <see cref="DefaultMessageButton" /> to <see cref="ResultMessage" />. /// </summary> /// <param name="defaultResult">The default result.</param> /// <returns>The result message.</returns> public static ResultMessage DefaultMessageButtonToResultMessage(DefaultMessageButton defaultResult) { ResultMessage result; switch (defaultResult) { case DefaultMessageButton.ButtonAbort: result = ResultMessage.ButtonAbort; break; case DefaultMessageButton.ButtonRetry: result = ResultMessage.ButtonRetry; break; case DefaultMessageButton.ButtonIgnore: result = ResultMessage.ButtonIgnore; break; case DefaultMessageButton.ButtonOk: result = ResultMessage.ButtonOk; break; case DefaultMessageButton.ButtonCancel: result = ResultMessage.ButtonCancel; break; case DefaultMessageButton.ButtonYes: result = ResultMessage.ButtonYes; break; case DefaultMessageButton.ButtonNo: result = ResultMessage.ButtonNo; break; case DefaultMessageButton.ButtonNone: result = ResultMessage.NoButton; break; default: throw new ArgumentOutOfRangeException("defaultResult"); } return(result); }
/// <summary> /// Converts <see cref="DefaultMessageButton" /> to <see cref="MessageBoxResult" />. /// </summary> /// <param name="defaultResult">The default result.</param> /// <returns>The message box result.</returns> /// <exception cref="System.ArgumentOutOfRangeException"> /// defaultResult /// or /// defaultResult /// or /// defaultResult /// or /// defaultResult /// </exception> public static MessageBoxResult DefaultMessageButtonToMessageBoxResult(DefaultMessageButton defaultResult) { MessageBoxResult messageBoxDefaultResult; switch (defaultResult) { case DefaultMessageButton.ButtonAbort: throw new ArgumentOutOfRangeException("defaultResult"); case DefaultMessageButton.ButtonRetry: throw new ArgumentOutOfRangeException("defaultResult"); case DefaultMessageButton.ButtonIgnore: throw new ArgumentOutOfRangeException("defaultResult"); case DefaultMessageButton.ButtonOk: messageBoxDefaultResult = MessageBoxResult.OK; break; case DefaultMessageButton.ButtonCancel: messageBoxDefaultResult = MessageBoxResult.Cancel; break; case DefaultMessageButton.ButtonYes: messageBoxDefaultResult = MessageBoxResult.Yes; break; case DefaultMessageButton.ButtonNo: messageBoxDefaultResult = MessageBoxResult.No; break; case DefaultMessageButton.ButtonNone: messageBoxDefaultResult = MessageBoxResult.None; break; default: throw new ArgumentOutOfRangeException("defaultResult"); } return(messageBoxDefaultResult); }
/// <summary> /// Displays the message. /// </summary> /// <param name="owner">Owner window</param> /// <param name="message">The message to display in the message box.</param> /// <param name="caption">The caption to display in the title bar of the message box.</param> /// <param name="button">One of the <see cref="MessageButton" /> values that specifies which buttons to display in the message box.</param> /// <param name="messageType">One of the <see cref="MessageType" /> values that specifies which image to display in the message box.</param> /// <param name="defaultResult">Default result.</param> /// <returns>One of the <see cref="ResultMessage" /> values.</returns> public ResultMessage DisplayMessage(Window owner, string message, string caption, MessageButton button, MessageType messageType, DefaultMessageButton defaultResult) { if (this.baseHost.IsService) { return(EnumConverter.DefaultMessageButtonToResultMessage(defaultResult)); } if (!this.Dispatcher.CheckAccess()) { return((ResultMessage)this.Dispatcher.Invoke((Func <ResultMessage>)(() => this.DisplayMessage(owner, message, caption, button, messageType, defaultResult)))); } var viewModel = new MessageBoxVm(caption, message, button, messageType, defaultResult); var view = new MessageBoxVw { DataContext = viewModel, Owner = owner }; var toggleMessageAgent = this.ToggleMessageAgent; if ((button == MessageButton.ButtonsOk) && (toggleMessageAgent != null)) { this.OnToggleMessageAgent(true, message, messageType); } else { if (view.Owner == null) { if ((Application.Current != null) && (Application.Current.MainWindow != null)) { view.Owner = Application.Current.MainWindow; view.WindowStartupLocation = WindowStartupLocation.CenterOwner; } else { view.WindowStartupLocation = WindowStartupLocation.CenterScreen; } } else { view.WindowStartupLocation = WindowStartupLocation.CenterOwner; } this.OnToggleMessageBoxShadow(true); view.ShowDialog(); this.OnToggleMessageBoxShadow(false); } return(viewModel.ResultMessage); }
/// <summary> /// Initializes a new instance of the <see cref="StandardButtonDialogFrameVm"/> class. /// </summary> /// <param name="title">The title.</param> /// <param name="buttons">The buttons.</param> /// <param name="defaultButton">The default button.</param> public StandardButtonDialogFrameVm(string title, MessageButton buttons, DefaultMessageButton defaultButton) { this.Title = title; this.messageButtons = buttons; this.defaultButton = defaultButton; if (this.defaultButton != DefaultMessageButton.ButtonNone) { switch (this.messageButtons) { case MessageButton.ButtonsOk: this.IsOkButtonVisible = true; this.IsCancelButtonVisible = false; this.IsRetryButtonVisible = false; this.IsAbortButtonVisible = false; this.IsIgnoreButtonVisible = false; this.IsYesButtonVisible = false; this.IsNoButtonVisible = false; this.OkCommand = new DelegateCommand(this.OkCommandHandler); break; case MessageButton.ButtonsOkCancel: this.IsOkButtonVisible = true; this.IsCancelButtonVisible = true; this.IsRetryButtonVisible = false; this.IsAbortButtonVisible = false; this.IsIgnoreButtonVisible = false; this.IsYesButtonVisible = false; this.IsNoButtonVisible = false; this.OkCommand = new DelegateCommand(this.OkCommandHandler); this.CancelCommand = new DelegateCommand(this.CancelCommandHandler); break; case MessageButton.ButtonsRetryCancel: this.IsOkButtonVisible = false; this.IsCancelButtonVisible = true; this.IsRetryButtonVisible = true; this.IsAbortButtonVisible = false; this.IsIgnoreButtonVisible = false; this.IsYesButtonVisible = false; this.IsNoButtonVisible = false; this.RetryCommand = new DelegateCommand(this.RetryCommandHandler); this.CancelCommand = new DelegateCommand(this.CancelCommandHandler); break; case MessageButton.ButtonsAbortRetryIgnore: this.IsOkButtonVisible = false; this.IsCancelButtonVisible = false; this.IsRetryButtonVisible = true; this.IsAbortButtonVisible = true; this.IsIgnoreButtonVisible = true; this.IsYesButtonVisible = false; this.IsNoButtonVisible = false; this.AbortCommand = new DelegateCommand(this.AbortCommandHandler); this.RetryCommand = new DelegateCommand(this.RetryCommandHandler); this.IgnoreCommand = new DelegateCommand(this.IgnoreCommandHandler); break; case MessageButton.ButtonsYesNo: this.IsOkButtonVisible = false; this.IsCancelButtonVisible = false; this.IsRetryButtonVisible = false; this.IsAbortButtonVisible = false; this.IsIgnoreButtonVisible = false; this.IsYesButtonVisible = true; this.IsNoButtonVisible = true; this.YesCommand = new DelegateCommand(this.YesCommandHandler); this.NoCommand = new DelegateCommand(this.NoCommandHandler); break; case MessageButton.ButtonsYesNoCancel: this.IsOkButtonVisible = false; this.IsCancelButtonVisible = true; this.IsRetryButtonVisible = false; this.IsAbortButtonVisible = false; this.IsIgnoreButtonVisible = false; this.IsYesButtonVisible = true; this.IsNoButtonVisible = true; this.YesCommand = new DelegateCommand(this.YesCommandHandler); this.NoCommand = new DelegateCommand(this.NoCommandHandler); this.CancelCommand = new DelegateCommand(this.CancelCommandHandler); break; default: throw new ArgumentOutOfRangeException("buttons"); } } }