/// <summary> /// The button click. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> private void ButtonClick(object sender, RoutedEventArgs e) { if (sender == this.ButtonOk) { result = MessageBoxResult.OK; } else if (sender == this.ButtonYes) { result = MessageBoxResult.Yes; } else if (sender == this.ButtonNo) { result = MessageBoxResult.No; } else if (sender == this.ButtonCancel) { result = MessageBoxResult.Cancel; } else { result = MessageBoxResult.None; } messageBox.Close(); messageBox = null; }
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); }