/// <summary> /// Displays a message box that has a message, title bar caption, button, and icon; and that returns a result. /// </summary> /// <param name="owner">The window owning the message box.</param> /// <param name="messageBoxText">A string that specifies the text to display.</param> /// <param name="icon">A MessageBoxImage value that specifies the icon to display.</param> /// <param name="button">A MessageBoxButton value that specifies which button or buttons to display.</param> /// <param name="caption">A string that specifies the title bar caption to display.</param> public static MessageBoxResult Show(System.Windows.Window owner, string messageBoxText, MessageBoxImage icon = MessageBoxImage.None, MessageBoxButton button = MessageBoxButton.OK, string caption = null) { var msg = new MessageBoxWindow(messageBoxText, caption, button, icon); // Imposta l'owner e usa lo stesso tema if (owner != null) { msg.Owner = owner; msg.WindowStartupLocation = WindowStartupLocation.CenterOwner; if (Theming.GetTheme(owner) is Theme theme) { Theming.SetTheme(msg, theme); } } // Attendi la risposta msg.ShowDialog(); return(msg.Result); }
internal MessageBoxWindow(string message, string caption, MessageBoxButton button, MessageBoxImage icon) { InitializeComponent(); // Imposta testo Message.Text = message; Title = caption ?? Process.GetCurrentProcess().ProcessName; // Imposta bottoni switch (button) { case MessageBoxButton.OKCancel: Button_Yes.Visibility = Visibility.Collapsed; Button_No.Visibility = Visibility.Collapsed; Button_OK.Content = Helper.GetOk(); Button_Cancel.Content = Helper.GetCancel(); Button_OK.Focus(); Theming.SetAccented(Button_OK, true); break; case MessageBoxButton.YesNo: Button_OK.Visibility = Visibility.Collapsed; Button_Cancel.Visibility = Visibility.Collapsed; Button_Yes.Content = Helper.GetYes(); Button_No.Content = Helper.GetNo(); Button_Yes.Focus(); Theming.SetAccented(Button_Yes, true); break; case MessageBoxButton.YesNoCancel: Button_OK.Visibility = Visibility.Collapsed; Button_Yes.Content = Helper.GetYes(); Button_No.Content = Helper.GetNo(); Button_Cancel.Content = Helper.GetCancel(); Button_Yes.Focus(); break; case MessageBoxButton.OK: Button_Yes.Visibility = Visibility.Collapsed; Button_No.Visibility = Visibility.Collapsed; Button_Cancel.Visibility = Visibility.Collapsed; Button_OK.Content = Helper.GetOk(); Button_OK.Focus(); break; } // Imposta icona switch (icon) { case MessageBoxImage.Exclamation: // Enumeration value 48 - also covers "Warning" Image.Content = "\uE7BA"; Image.Visibility = Visibility.Visible; break; case MessageBoxImage.Error: // Enumeration value 16, also covers "Hand" and "Stop" Image.Content = "\uEA39"; Image.Visibility = Visibility.Visible; break; case MessageBoxImage.Information: // Enumeration value 64 - also covers "Asterisk" Image.Content = "\uE946"; Image.Visibility = Visibility.Visible; break; case MessageBoxImage.Question: Image.Content = "\uE9CE"; Image.Visibility = Visibility.Visible; break; } }