private async void RunSample() { var message = new TextMessage("Set Text to Foo?", "Update Text", MessageButton.YesNo); var result = await Messenger.Default.SendAsync(message); if (result.Result == MessageResult.Yes) SampleProperty = "Foo"; }
public static void ShowTextMessage(TextMessage message) { if (message.Button == TextMessage.MessageButton.OK) MessageBox.Show(message.Text, message.Title, MessageBoxButton.OK); else if(message.Button == TextMessage.MessageButton.OKCancel) { var result = MessageBox.Show(message.Text, message.Title, MessageBoxButton.OKCancel); message.Result = result == MessageBoxResult.OK ? TextMessage.MessageResult.OK : TextMessage.MessageResult.Cancel; } }
protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e) { TextMessage msg = null; if (!Model.Person.IsValid) msg = new TextMessage("Not valid", "Discard?", TextMessage.MessageButton.OKCancel); // TODO use strings from resource file if (msg != null) { Messenger.Send(msg); if (msg.Result == TextMessage.MessageResult.OK) App.Persons.Remove(Model.Person); else e.Cancel = true; } else App.Persons.Add(Model.Person); }
protected void BackKeyPressHandler(CancelEventArgs e) { if (!Model.Person.IsValid) { var msg = new TextMessage("Not valid", "Discard?", MessageButton.OKCancel); // TODO use strings from resource file msg.SuccessCallback += result => { if (result == MessageResult.Ok) { App.Persons.Remove(Model.Person); NavigationService.GoBack(); } }; e.Cancel = true; Messenger.Default.Send(msg); } else App.Persons.Add(Model.Person); }
private static async Task GetTextMessageImplementation(TextMessage message) { if (message.Button == MessageButton.OK) { var msg = new MessageDialog(message.Text, message.Title); await msg.ShowAsync(); } else { var msg = new MessageDialog(message.Text, message.Title); if (message.Button == MessageButton.OKCancel) { msg.Commands.Add(new UICommand(Strings.ButtonOk)); msg.Commands.Add(new UICommand(Strings.ButtonCancel)); } else if (message.Button == MessageButton.YesNoCancel || message.Button == MessageButton.YesNo) { msg.Commands.Add(new UICommand(Strings.ButtonYes)); msg.Commands.Add(new UICommand(Strings.ButtonNo)); if (message.Button == MessageButton.YesNoCancel) msg.Commands.Add(new UICommand(Strings.ButtonCancel)); } msg.DefaultCommandIndex = 0; msg.CancelCommandIndex = 1; var cmd = await msg.ShowAsync(); var index = msg.Commands.IndexOf(cmd); if (message.Button == MessageButton.OKCancel) message.CallSuccessCallback(index == 0 ? MessageResult.Ok : MessageResult.Cancel); else if (message.Button == MessageButton.YesNoCancel) message.CallSuccessCallback(index == 0 ? MessageResult.Yes : (index == 1 ? MessageResult.No : MessageResult.Cancel)); else if (message.Button == MessageButton.YesNo) message.CallSuccessCallback(index == 0 ? MessageResult.Yes : MessageResult.No); } }
private static async Task ShowTextMessage(TextMessage m) { if (m.Button == MessageButton.OK) { var msg = new MessageDialog(m.Text, m.Title); await msg.ShowAsync(); } else { var msg = new MessageDialog(m.Text, m.Title); if (m.Button == MessageButton.OKCancel) { msg.Commands.Add(new UICommand(Strings.ButtonOk)); msg.Commands.Add(new UICommand(Strings.ButtonCancel)); } else if (m.Button == MessageButton.YesNoCancel || m.Button == MessageButton.YesNo) { msg.Commands.Add(new UICommand(Strings.ButtonYes)); msg.Commands.Add(new UICommand(Strings.ButtonNo)); if (m.Button == MessageButton.YesNoCancel) msg.Commands.Add(new UICommand(Strings.ButtonCancel)); } msg.DefaultCommandIndex = 0; msg.CancelCommandIndex = 1; var cmd = await msg.ShowAsync(); var index = msg.Commands.IndexOf(cmd); if (m.Button == MessageButton.OKCancel) m.Result = index == 0 ? MessageResult.OK : MessageResult.Cancel; else if (m.Button == MessageButton.YesNoCancel) m.Result = index == 0 ? MessageResult.Yes : (index == 1 ? MessageResult.No : MessageResult.Cancel); else if (m.Button == MessageButton.YesNo) m.Result = index == 0 ? MessageResult.Yes : MessageResult.No; } }
/// <summary>Closes the given document and saves it if needed. </summary> /// <param name="document">The document to close. </param> /// <returns>The task. </returns> public async Task<bool> CloseDocumentAsync(JsonDocumentModel document) { if (document.UndoRedoManager.CanUndo) { var message = new TextMessage(string.Format(Strings.MessageSaveDocumentText, document.DisplayTitle), Strings.MessageSaveDocumentTitle, MessageButton.YesNoCancel); var result = await Messenger.Default.SendAsync(message); if (result.Result == MessageResult.Cancel) return false; if (result.Result == MessageResult.Yes) await SaveDocumentAsync(document); } RemoveDocument(document); return true; }