public MessageBoxResult Show(string msgText, string caption, MessageBoxButton button) { var vm = new MessageBoxWindowViewModel(button, msgText, caption); var msg = new MessageBoxWindow { WindowStartupLocation = System.Windows.WindowStartupLocation.CenterOwner, DataContext = vm }; if (ShellService.Current.Shell is System.Windows.Window shell && shell.IsLoaded) { msg.ShowInTaskbar = false; msg.Owner = shell; } var res = msg.ShowDialog(); #if DEBUG ThreadInvoker.BackInvoke(() => { Thread.Sleep(1000); for (int i = 0; i < 10; i++) { System.GC.Collect(); System.GC.WaitForPendingFinalizers(); } }); #endif msg.DataContext = null; switch (vm.DialogResult) { case null: if (button == MessageBoxButton.YesNoCancel) { return(MessageBoxResult.Cancel); } return(MessageBoxResult.None); case false: return(MessageBoxResult.No); case true: if (button == MessageBoxButton.OK) { return(MessageBoxResult.OK); } return(MessageBoxResult.Yes); default: return(MessageBoxResult.None); } }
///<summary> ///Creates MessageBox ///</summary> ///<param name="title"> ///Title displayed on top of the window ///</param> ///<param name="message"> ///Message displayed in window ///</param> ///<param name="closeApp"> ///If true, app will closed if you press on cross button ///</param> public static MessageBoxWindow CreateMessageBox(string title, string message, bool closeApp = false) { var msgbox = new MessageBoxWindow(closeApp); var msgboxView = new MessageBoxWindowViewModel(title, message); msgboxView.CloseButtonCommand = ReactiveCommand.Create(() => { if (msgbox.CloseApp) { msgbox.CloseApp = false; } msgbox.Close(); }); msgbox.DataContext = msgboxView; return(msgbox); }
/// <inheritdoc cref="IMessageBoxCompatService.ShowAsync(string, string, MessageBoxButtonCompat, MessageBoxImageCompat?)"/> public static async Task <MessageBoxResultCompat> ShowAsync( string messageBoxText, string caption, MessageBoxButtonCompat button, MessageBoxImageCompat?icon = null) { var f = DI.Get_Nullable <IMessageBoxCompatService>(); if (f != null) { return(await f.ShowAsync(messageBoxText, caption, button, icon)); } var viewModel = new MessageBoxWindowViewModel { Content = messageBoxText, IsCancelcBtn = button == MessageBoxButtonCompat.OKCancel, }; var r = await IShowWindowService.Instance.ShowDialog( CustomWindow.MessageBox, viewModel, caption, ResizeModeCompat.NoResize); return(r ? MessageBoxResultCompat.OK : MessageBoxResultCompat.Cancel); }
/// <inheritdoc cref="IMessageBoxService.ShowAsync(string, string, Button, Image)"/> public static async Task <Result> ShowAsync( string messageBoxText, string caption = default_caption, Button button = default_button, Image icon = default, DontPromptType rememberChooseKey = default) { if (mbcs != null) { return(await mbcs.ShowAsync(messageBoxText, caption, button, icon)); } var isDoNotShow = rememberChooseKey != DontPromptType.Undefined; if (isDoNotShow && UISettings.DoNotShowMessageBoxs.Value?.Contains(rememberChooseKey) == true) { return(Result.OK); } var viewModel = new MessageBoxWindowViewModel { Content = messageBoxText, IsCancelcBtn = button == OKCancel, IsShowRememberChoose = isDoNotShow, }; var r = await IWindowManager.Instance.ShowDialog( CustomWindow.MessageBox, viewModel, caption, ResizeMode.NoResize); if (r && viewModel.RememberChoose && isDoNotShow) { if (UISettings.DoNotShowMessageBoxs.Value?.Contains(rememberChooseKey) == false) { UISettings.DoNotShowMessageBoxs.Value?.Add(rememberChooseKey); } UISettings.DoNotShowMessageBoxs.RaiseValueChanged(); } return(r ? Result.OK : Result.Cancel); }
public MessageBoxWindow(MessageBoxWindowViewModel viewmodel) { this.DataContext = viewmodel; InitializeComponent(); }