/// <summary> /// The set image of message box. /// </summary> /// <param name="image"> /// The image. /// </param> private static void SetImageOfMessageBox(MessageBoxImage image) { switch (image) { case MessageBoxImage.Warning: messageBox.SetImage("Warning.png"); break; case MessageBoxImage.Question: messageBox.SetImage("Question.png"); break; case MessageBoxImage.Information: messageBox.SetImage("Information.png"); break; case MessageBoxImage.Error: messageBox.SetImage("Cancel1.bmp"); break; case MessageBoxImage.None: break; default: messageBox.Image.Visibility = Visibility.Collapsed; break; } }
public static MessageBoxResult Show( string caption, string text, MessageBoxButton button, string image, Brush backgroundBrush = null, Brush borderBrush = null, Color?titleBarColor1 = null, Color?titleBarColor2 = null, Color?mainAreaColor1 = null, Color?mainAreaColor2 = null) { messageBox = new ImprovedMessageBox { TextBlockMessage = { Text = text }, MessageTitle = { Text = caption } }; /*var color1 = (Color)ColorConverter.ConvertFromString("#26508A"); // Color.FromArgb(255, 38, 80, 138) * var color2 = (Color)ColorConverter.ConvertFromString("#2A739E"); // Color.FromArgb(255, 42, 115, 158) * var color3 = (Color)ColorConverter.ConvertFromString("#70A4B9"); // Color.FromArgb(255, 112, 164, 185) * var color4 = (Color)ColorConverter.ConvertFromString("#CDDFE9"); // Color.FromArgb(255, 205, 223, 233) */ if (backgroundBrush != null) { messageBox.WindowMessageBox.Background = backgroundBrush; } if (borderBrush != null) { messageBox.Border.BorderBrush = borderBrush; } try { if (titleBarColor1 != null && titleBarColor2 != null) { messageBox.GradientStopColorForTitleBar.Color = (Color)titleBarColor1; messageBox.GradientStopColorForTitleBar2.Color = (Color)titleBarColor2; } else if (titleBarColor1 != null || titleBarColor2 != null) { throw new NotSupportedException("Please specify both the colors!"); } if (mainAreaColor1 != null && mainAreaColor2 != null) { messageBox.GradientStopColorForMainArea.Color = (Color)mainAreaColor1; messageBox.GradientStopColorForMainArea2.Color = (Color)mainAreaColor2; } else if (mainAreaColor1 != null || mainAreaColor2 != null) { throw new NotSupportedException("Please specify both the colors!"); } } catch (Exception e) { messageBox.TextBlockMessage.Text = e.Message; } SetVisibilityOfButtons(button); try { if (!string.IsNullOrEmpty(image)) { messageBox.SetImage(image); messageBox.Image.Visibility = Visibility.Visible; } } catch (Exception e) { messageBox.TextBlockMessage.Text = e.Message; } messageBox.ShowDialog(); return(result); }