public static void ShowOKDialog(DialogHost host, string message) { var card = new MaterialDesignThemes.Wpf.Card { Padding = new System.Windows.Thickness(32), Margin = new System.Windows.Thickness(16), Width = 350 }; var stackPanel = new StackPanel { HorizontalAlignment = HorizontalAlignment.Center }; var textBlock = new TextBlock { Text = message, TextWrapping = TextWrapping.Wrap }; var okButton = new Button { Content = "OK", Width = 100 }; Style btnstyle = Application.Current.FindResource("MaterialDesignFlatButton") as Style; if (btnstyle != null) { okButton.Style = btnstyle; } okButton.Click += (sender, args) => host.IsOpen = false; stackPanel.Children.Add(textBlock); stackPanel.Children.Add(okButton); card.Content = stackPanel; host?.ShowDialog(card); }
/// <summary> /// Shows a new <see cref="OpenMultipleDirectoriesDialog" />. /// </summary> /// <param name="dialogHost">The <see cref="DialogHost" /></param> /// <param name="args">The arguments for the dialog initialization</param> /// <returns></returns> public static async Task <OpenMultipleDirectoriesDialogResult> ShowDialogAsync(DialogHost dialogHost, OpenMultipleDirectoriesDialogArguments args) { OpenMultipleDirectoriesDialog dialog = InitDialog( args.Width, args.Height, args.CurrentDirectory, args.CreateNewDirectoryEnabled, args.ShowHiddenFilesAndDirectories, args.ShowSystemFilesAndDirectories, args.SwitchPathPartsAsButtonsEnabled, args.PathPartsAsButtons ); return(await dialogHost.ShowDialog(dialog, args.OpenedHandler, args.ClosingHandler) as OpenMultipleDirectoriesDialogResult); }
public static async Task <bool> ShowConfirmationDialog(string message) { DialogHost dialogHost = MessageBoxHelper.GetActiveWindowDialogHost(); if (dialogHost != null && !isDialogShown) { MessageBoxHelper.isDialogShown = true; dialogHost.DialogClosing += ConfirmationDialogHost_DialogClosing; await dialogHost.ShowDialog(new ConfirmationDialogControl(message)); dialogHost.DialogClosing -= ConfirmationDialogHost_DialogClosing; MessageBoxHelper.isDialogShown = false; } return(MessageBoxHelper.lastConfirmationResult); }
/// <summary> /// Shows a new <see cref="SaveFileDialog" />. /// </summary> /// <param name="dialogHost">The <see cref="DialogHost" /></param> /// <param name="args">The arguments for the dialog initialization</param> /// <returns></returns> public static async Task <SaveFileDialogResult> ShowDialogAsync(DialogHost dialogHost, SaveFileDialogArguments args) { SaveFileDialog dialog = InitDialog( args.Width, args.Height, args.CurrentDirectory, args.Filename, args.Filters, args.FilterIndex, args.CreateNewDirectoryEnabled, args.ShowHiddenFilesAndDirectories, args.ShowSystemFilesAndDirectories ); return(await dialogHost.ShowDialog(dialog, args.OpenedHandler, args.ClosingHandler) as SaveFileDialogResult); }
public static async Task <UserDialogResult> ShowUserDialog(UserViewModel user) { DialogHost dialogHost = MessageBoxHelper.GetActiveWindowDialogHost(); if (dialogHost != null && !isDialogShown) { MessageBoxHelper.isDialogShown = true; dialogHost.DialogClosing += UserDialogHost_DialogClosing; await dialogHost.ShowDialog(new UserDialogControl(user)); dialogHost.DialogClosing -= UserDialogHost_DialogClosing; MessageBoxHelper.isDialogShown = false; } return(MessageBoxHelper.lastUserResult); }
public static async Task <string> ShowCustomDialog(UserControl control) { DialogHost dialogHost = MessageBoxHelper.GetActiveWindowDialogHost(); if (!isDialogShown) { MessageBoxHelper.isDialogShown = true; dialogHost.DialogClosing += CustomDialogHost_DialogClosing; await dialogHost.ShowDialog(control); dialogHost.DialogClosing -= CustomDialogHost_DialogClosing; MessageBoxHelper.isDialogShown = false; } return(MessageBoxHelper.lastCustomResult); }
public static async Task <string> ShowTextEntryDialog(string textEntryName, string defaultValue = null) { BasicTextEntryDialogControl textEntryControl = new BasicTextEntryDialogControl(textEntryName, defaultValue); DialogHost dialogHost = MessageBoxHelper.GetActiveWindowDialogHost(); if (dialogHost != null && !isDialogShown) { MessageBoxHelper.isDialogShown = true; dialogHost.DialogClosing += ConfirmationDialogHost_DialogClosing; await dialogHost.ShowDialog(textEntryControl); dialogHost.DialogClosing -= ConfirmationDialogHost_DialogClosing; MessageBoxHelper.isDialogShown = false; } return((MessageBoxHelper.lastConfirmationResult) ? textEntryControl.TextEntry : null); }
public static async Task <string> ShowTimedCustomDialog(UserControl control, int timeout) { DialogHost dialogHost = MessageBoxHelper.GetActiveWindowDialogHost(); if (!isDialogShown) { MessageBoxHelper.isDialogShown = true; await dialogHost.ShowDialog(control, async delegate(object sender, DialogOpenedEventArgs args) { await Task.Delay(timeout); args.Session.Close(false); }); MessageBoxHelper.isDialogShown = false; } return(MessageBoxHelper.lastCustomResult); }
public static async Task <object> ShowDialog(UserControl control) { IEnumerable <Window> windows = Application.Current.Windows.OfType <Window>(); if (windows.Count() > 0) { object obj = windows.FirstOrDefault().FindName("MDDialogHost"); if (obj != null) { DialogHost dialogHost = (DialogHost)obj; dialogHost.DialogClosing += DialogHost_DialogClosing; await dialogHost.ShowDialog(control); dialogHost.DialogClosing -= DialogHost_DialogClosing; } } return(lastResult); }
private Task <object> ShowDialog(object content, DialogOpenedEventHandler openedEventHandler, DialogClosingEventHandler dialogClosingEventHandler) { HashSet <DialogHost> instances = (HashSet <DialogHost>)dialogInstancesField.GetValue(null); if (instances != null) { if (instances.Count == 0) { throw new InvalidOperationException("No loaded DialogHost instances."); } DialogHost host = instances.First(); if (host.IsOpen) { host.IsOpen = false; } return(host.ShowDialog(content, openedEventHandler, dialogClosingEventHandler)); } return(DialogHost.Show(content, openedEventHandler, dialogClosingEventHandler)); }
//Show a Material Design Ok Dialog public static async Task ShowOkDialog(this DialogHost host, string title, string message) { CloseDia(host); StackPanel vPanel = new StackPanel { Margin = new Thickness(5) }; Label header = new Label { Content = title, VerticalAlignment = VerticalAlignment.Top, HorizontalAlignment = HorizontalAlignment.Left, Margin = new Thickness(5), FontWeight = FontWeights.Bold }; header.FontSize++; Label content = new Label { Content = message, VerticalAlignment = VerticalAlignment.Top, HorizontalAlignment = HorizontalAlignment.Left, Margin = new Thickness(5) }; Button ok = new Button { Content = strings.ok, Foreground = Brushes.Gray, Width = 60, Margin = new Thickness(3), Style = (Style)host.FindResource("MaterialDesignFlatButton"), HorizontalAlignment = HorizontalAlignment.Right }; ok.Click += delegate { CloseDia(host); }; vPanel.Children.Add(header); vPanel.Children.Add(content); vPanel.Children.Add(ok); await host.ShowDialog(vPanel); }
/// <summary> /// 弹出消息对话框 /// </summary> /// <param name="content">消息内容</param> public static void ShowMessage(string content, MessageBoxButton button, Action <MessageBoxResult> callback = null) { DialogHost dh = BuildDialogHost("message"); if (dh == null) { return; } dh.ShowDialog(new MessageDialog { Message = { Text = content }, Button = button }, delegate(object sender, DialogClosingEventArgs args) { bool parameter = false; bool.TryParse(args.Parameter.ToString(), out parameter); if (callback != null) { callback(BuildResult(parameter, button)); } }); }
private async Task DialogOk(string text, string caption) { CloseDialog(); StackPanel vPanel = new StackPanel { Margin = new Thickness(10), MinWidth = 150, MinHeight = 70 }; Label captionLabel = new Label { Content = caption, HorizontalAlignment = HorizontalAlignment.Left, FontWeight = FontWeights.Bold }; Label contentLabel = new Label { Content = text, HorizontalAlignment = HorizontalAlignment.Left }; Button ok = new Button { Content = "Ok", Foreground = Brushes.Gray, Width = 60, Margin = new Thickness(3), HorizontalAlignment = HorizontalAlignment.Right }; ok.Click += delegate { CloseDialog(); }; vPanel.Children.Add(captionLabel); vPanel.Children.Add(contentLabel); vPanel.Children.Add(ok); await DialogHost.ShowDialog(vPanel); }
private void ApplicationStart(object sender, StartupEventArgs e) { //Disable shutdown when the dialog closes Current.ShutdownMode = ShutdownMode.OnExplicitShutdown; var dialog = new DialogHost(); dialog.ShowDialog("Please wait for the system to extract"); if (dialog.IsOpen == true) { var mainWindow = new MainWindow(); //Re-enable normal shutdown mode. Current.ShutdownMode = ShutdownMode.OnMainWindowClose; Current.MainWindow = mainWindow; mainWindow.Show(); } else { MessageBox.Show("Unable to load data.", "Error", MessageBoxButton.OK); Current.Shutdown(-1); } }
private async void Show_About(object sender, RoutedEventArgs e) { var dialog = new dialogs.About(); var result = await DialogHost.ShowDialog(dialog); }
public static async Task ShowErrorDialog(string message, DialogHost host) { CloseDialog(host); await host.ShowDialog(new ErrorDialog(message).GetContent()); }
/// <summary> /// Shows a new <see cref="AlertDialog" />. /// </summary> /// <param name="dialogHost">The <see cref="DialogHost" /></param> /// <param name="args">The arguments for the dialog initialization</param> /// <returns></returns> public static async Task ShowDialogAsync(DialogHost dialogHost, AlertDialogArguments args) { AlertDialog dialog = InitDialog(args); await dialogHost.ShowDialog(dialog, args.OpenedHandler, args.ClosingHandler); }
/// <summary> /// /// </summary> /// <returns></returns> public async Task <object> ShowAsync(DialogHost host = null) { return(await(host == null ? DialogHost.Show(this, "RootDialog", OpenedEventHandler, ClosingEventHandler) : host.ShowDialog(this, OpenedEventHandler, ClosingEventHandler))); }