private static void Click(object o, RoutedEventArgs e) { Button button = (Button)o; switch (button.Name) { case "Confirm": SelectdItem = MyMessageBoxResult.Comfirm; break; case "No": SelectdItem = MyMessageBoxResult.No; break; case "Buttons": SelectdItem = MyMessageBoxResult.Buttons; break; } ((Window)button.Tag).Close(); }
/// <summary> /// 弹出提示窗口 /// </summary> /// <param name="Text">弹窗内容</param> /// <param name="TitleText">弹窗标题</param> /// <param name="myMessageBoxButton">按钮配置</param> /// <param name="ConfirmText">确认按钮信息</param> /// <param name="NoText">取消按钮信息</param> /// <param name="ButtonText">自定义按钮信息</param> /// <returns></returns> public static MyMessageBoxResult Show(string Text, string TitleText = "标题", MyMessageBoxButton myMessageBoxButton = MyMessageBoxButton.Confirm, string ConfirmText = "是", string NoText = "否", string ButtonText = "取消") { Window window = new Window { FontSize = 16.0, Height = 180.0, Width = 300.0, MaxHeight = 180.0, MaxWidth = 300.0, MinHeight = 180.0, MinWidth = 300.0, BorderThickness = new Thickness { Top = 0.0, Bottom = 0.0, Left = 0.0, Right = 0.0 }, Title = TitleText, WindowStartupLocation = WindowStartupLocation.CenterScreen, WindowStyle = WindowStyle.ToolWindow }; Grid grid = new Grid(); Canvas canvas = new Canvas { Margin = new Thickness { Left = 0.0, Top = 0.0, Right = 0.0, Bottom = 30.0 } }; Canvas canvas2 = new Canvas { Margin = new Thickness { Left = 0.0, Top = 110.0, Right = 0.0, Bottom = 0.0 }, Background = Brushes.Gray }; TextBlock textBlock = new TextBlock { FontSize = 16.0, TextAlignment = TextAlignment.Left, TextWrapping = TextWrapping.WrapWithOverflow, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness { Left = 10.0 }, MaxHeight = 108.0, MaxWidth = 274.0 }; Button button = new Button { Margin = new Thickness { Top = 5.0, Left = 10.0 }, Name = "Confirm" }; button.Click += Click; button.FontSize = 14.0; button.Tag = window; button.MinWidth = 50.0; Button button2 = new Button { Margin = new Thickness { Top = 5.0, Left = 115.0 }, Name = "No" }; button2.Click += Click; button2.FontSize = 14.0; button2.Tag = window; button2.MinWidth = 50.0; Button button3 = new Button { Margin = new Thickness { Top = 5.0, Left = 215.0 }, Name = "Buttons" }; button3.Click += Click; button3.FontSize = 14.0; button3.Tag = window; button3.MinWidth = 50.0; textBlock.Text = Text; button3.Content = ButtonText; button.Content = ConfirmText; button2.Content = NoText; switch (myMessageBoxButton) { case MyMessageBoxButton.Confirm: canvas2.Children.Add(button); break; case MyMessageBoxButton.ConfirmNO: canvas2.Children.Add(button); canvas2.Children.Add(button2); break; } canvas.Children.Add(textBlock);; grid.Children.Add(canvas); grid.Children.Add(canvas2); window.Content = grid; window.ShowDialog(); new Task(delegate { Thread.Sleep(200); SelectdItem = MyMessageBoxResult.None; }).Start(); return(SelectdItem); }