public static MessageBoxResult Show(Window owner, string message, MessageBoxButton button = MessageBoxButton.OK, AyMessageBoxImage icon = AyMessageBoxImage.None, MessageBoxResult defaultResult = MessageBoxResult.None, MessageBoxOptions options = MessageBoxOptions.None) { return(Show(owner, message, string.Empty, button, icon, defaultResult, options)); }
public static MessageBoxResult Show(string message, string title = "", MessageBoxButton button = MessageBoxButton.OK, AyMessageBoxImage icon = AyMessageBoxImage.None, MessageBoxResult defaultResult = MessageBoxResult.None, MessageBoxOptions options = MessageBoxOptions.None) { return(Show(null, message, title, button, icon, defaultResult, options)); }
public static MessageBoxResult Show(Window owner, string message, string title = "", MessageBoxButton button = MessageBoxButton.OK, AyMessageBoxImage icon = AyMessageBoxImage.None, MessageBoxResult defaultResult = MessageBoxResult.None, MessageBoxOptions options = MessageBoxOptions.None) { var result = Application.Current.Dispatcher.Invoke(new Func <MessageBoxResult>(() => { var messageBox = new AyMessageBox(owner, message, title, button, icon, defaultResult, options, null, null, 1); messageBox.ShowDialog(); return(messageBox.MessageBoxResult); })); return((MessageBoxResult)result); }
/// <summary> /// Create the image from the system's icons /// </summary> /// <param name="icon"></param> private void CreateImage(AyMessageBoxImage icon) { switch (icon) { case AyMessageBoxImage.None: ImagePlaceholder.Visibility = Visibility.Collapsed; break; case AyMessageBoxImage.Information: ImagePlaceholder.Icon = "path_ay_msg_info"; ImagePlaceholder.Foreground = HexToBrush.FromHex("#909399"); break; case AyMessageBoxImage.Question: ImagePlaceholder.Icon = "path_ay_msg_question"; ImagePlaceholder.Foreground = HexToBrush.FromHex("#409EFF"); break; case AyMessageBoxImage.Warning: ImagePlaceholder.Icon = "path_ay_msg_warning"; ImagePlaceholder.Foreground = HexToBrush.FromHex("#E6A23C"); break; case AyMessageBoxImage.Error: ImagePlaceholder.Icon = "path_ay_msg_error"; ImagePlaceholder.Foreground = HexToBrush.FromHex("#F56C6C"); break; case AyMessageBoxImage.Delete: ImagePlaceholder.Icon = "path_ay_msg_delete"; ImagePlaceholder.Foreground = HexToBrush.FromHex("#F56C6C"); break; case AyMessageBoxImage.Right: ImagePlaceholder.Icon = "path_ay_msg_right"; ImagePlaceholder.Foreground = HexToBrush.FromHex("#67C473"); break; default: throw new ArgumentOutOfRangeException("icon"); } }
internal static MessageBoxResult Promt(Window owner, Action <AyFormInput> init, Action <string> callBack, string title = "", MessageBoxButton button = MessageBoxButton.OKCancel, AyMessageBoxImage icon = AyMessageBoxImage.None, MessageBoxResult defaultResult = MessageBoxResult.None, MessageBoxOptions options = MessageBoxOptions.None) { try { var result = Application.Current.Dispatcher.Invoke(new Func <MessageBoxResult>(() => { string a = null; var messageBox = new AyMessageBox(owner, a, title, button, icon, defaultResult, options, null, init, 1, callBack); messageBox.ShowDialog(); return(messageBox.MessageBoxResult); })); return((MessageBoxResult)result); } catch { return(MessageBoxResult.None); } }
/// <summary> /// 添加一个构造函数 /// </summary> /// <param name="owner">TMMessageBox拥有者</param> /// <param name="message"></param> /// <param name="details"></param> /// <param name="button"></param> /// <param name="icon"></param> /// <param name="defaultResult"></param> /// <param name="options"></param> /// <param name="promtcallback">promt回调</param> public AyMessageBox(Window owner, string message, string title, MessageBoxButton button, AyMessageBoxImage icon, MessageBoxResult defaultResult, MessageBoxOptions options, Action closeAction, Action <AyFormInput> Init, int _1, Action <string> promtcallback = null) { InitializeComponent(); this.Topmost = true; this.CloseOverride = closeAction; try { Owner = owner ?? Application.Current.MainWindow; } catch { } if (promtcallback != null) { AyFormInput afi = new AyFormInput(); afi.MinWidth = 160; afi.Width = double.NaN; afi.Margin = new Thickness(24, 20, 24, 20); afi.Rule = "required"; afi.VerticalAlignment = VerticalAlignment.Center; afi.HorizontalAlignment = HorizontalAlignment.Stretch; layout.Child = afi; if (Init.IsNotNull()) { Init(afi); } this.MinWidth = 360; var okButton = new Button { Name = "okButton", Content = Langs.share_ok.Lang(), IsDefault = defaultResult == MessageBoxResult.OK, Tag = MessageBoxResult.OK, Margin = new Thickness(10, 0, 0, 0) }; okButton.SetResourceReference(Button.StyleProperty, "Button.Primary"); okButton.Click += (ss, ee) => { if (afi.Validate()) { MessageBoxResult = (MessageBoxResult)(ss as Button).Tag; CloseTMMessageBox(); if (afi.IsPasswordBox) { promtcallback(afi.Password); } else { promtcallback(afi.Text); } } else { afi.Focus(); } }; ButtonsPanel.Children.Add(okButton); var cancelButton = new Button { Name = "cancelButton", Content = Langs.share_cancel.Lang(), IsDefault = defaultResult == MessageBoxResult.Cancel, IsCancel = true, Tag = MessageBoxResult.Cancel, Margin = new Thickness(6, 0, 4, 0) }; cancelButton.SetResourceReference(Button.StyleProperty, "Button.Default"); cancelButton.Click += ButtonClick; ButtonsPanel.Children.Add(cancelButton); ButtonsPanel.Margin = new Thickness(0, 0, 20, 16); } else { CreateButtons(button, defaultResult); CreateImage(icon); MessageText.Text = message; } if (title.IsEmptyAndNull()) { this.Title = Langs.share_tip.Lang(); } else { this.Title = title ?? ""; } this.Closed += Ay_Closed; this.SourceInitialized += new EventHandler(win_SourceInitialized); Showwindow(); this.Topmost = false; }