protected override void OnClosing(CancelEventArgs e) { if (IsDirty && CanSave) { var dlg = new MetroDialogWindow { Owner = this, Title = "Unsaved Changes", Width = Width, Message = $"Do you want to save changes to {Session.Title}?", ButtonStyle = MessageDialogStyle.AffirmativeAndNegativeAndSingleAuxiliary, AffirmativeButtonText = "save", NegativeButtonText = "don't save", }; dlg.ShowDialog(); if (dlg.Result == MessageDialogResult.Affirmative) { if (!Save(SaveOperation.Save)) { e.Cancel = true; return; } } else if (dlg.Result == MessageDialogResult.FirstAuxiliary) { e.Cancel = true; return; } } base.OnClosing(e); }
public static void Present(this UserPresentableException e, object uiContext = null) { Log.Error(TAG, $"{e.Message} ({e.Details})", e.InnerException ?? e); MainThread.Ensure(); var window = new MetroDialogWindow { Title = e.Message, Message = e.Details, AffirmativeButtonText = Catalog.GetString("OK") }; var ownerWindow = uiContext as Window; if (ownerWindow == null) { window.Owner = ownerWindow; window.Width = 400; window.WindowStartupLocation = WindowStartupLocation.CenterScreen; } else { window.Width = ownerWindow.Width; window.WindowStartupLocation = WindowStartupLocation.CenterOwner; } window.ShowDialog(); }
void IAlertMessageViewDelegate.DisplayMessage(Message message) { var affirmativeAction = message.AffirmativeAction; var negativeAction = message.NegativeAction; var auxiliaryAction = message.AuxiliaryAction; if (affirmativeAction == null) { return; } var dialog = new MetroDialogWindow { Owner = window, Width = window.Width, ButtonStyle = MessageDialogStyle.Affirmative, Title = message.Text, Message = message.DetailedText ?? message.Text }; dialog.AffirmativeButtonText = affirmativeAction.Label; if (negativeAction != null) { dialog.ButtonStyle = MessageDialogStyle.AffirmativeAndNegative; dialog.NegativeButtonText = negativeAction.Label; if (auxiliaryAction != null) { dialog.ButtonStyle = MessageDialogStyle.AffirmativeAndNegativeAndSingleAuxiliary; dialog.FirstAuxiliaryButtonText = auxiliaryAction.Label; } } dialogs.Add(message.Id, dialog); dialog.Closed += (sender, e) => { MessageAction action = null; switch (dialog.Result) { case MessageDialogResult.Affirmative: action = affirmativeAction; break; case MessageDialogResult.Negative: action = negativeAction; break; case MessageDialogResult.FirstAuxiliary: action = auxiliaryAction; break; } if (action != null && dialogs.ContainsKey(message.Id)) { message?.ActionResponseHandler(message, action); } }; dialog.ShowDialog(); }