private static string GetDefaultCaption(EnumPromptType type) { string caption = string.Empty; switch (type) { case EnumPromptType.Info: caption = "提示"; break; case EnumPromptType.Warn: caption = "警告"; break; case EnumPromptType.Error: caption = "错误"; break; case EnumPromptType.Success: caption = "成功"; break; default: break; } return(caption); }
public static MessageBoxResult Show(Window owner, string messageBoxText, string caption, MessageBoxButton button, EnumPromptType type) { return(MessageBoxModule.Show(owner, messageBoxText, caption, button, MessageBoxResult.OK, type)); }
public static MessageBoxResult Show(string messageBoxText, string caption, EnumPromptType type) { return(MessageBoxModule.Show(messageBoxText, caption, type)); }
public static MessageBoxResult Show(string messageBoxText, string caption, EnumPromptType type) { return(MessageBoxModule.Show(null, messageBoxText, caption, MessageBoxButton.OK, MessageBoxResult.OK, type)); }
public static MessageBoxResult Show(string messageBoxText, EnumPromptType type) { return(Show(messageBoxText, "", type)); }
public static MessageBoxResult Show(Window owner, string messageBoxText, string caption , MessageBoxButton button, MessageBoxResult defaultResult, EnumPromptType type) { MessageBoxModule messageBox = new MessageBoxModule(); if (owner != null) { //蒙板 Grid layer = new Grid() { Background = new SolidColorBrush(Color.FromArgb(128, 0, 0, 0)) }; //父级窗体原来的内容 UIElement original = owner.Content as UIElement; owner.Content = null; //容器Grid Grid container = new Grid(); container.Children.Add(original); //放入原来的内容 container.Children.Add(layer); //在上面放一层蒙板 //将装有原来内容和蒙板的容器赋给父级窗体 owner.Content = container; messageBox.WindowStartupLocation = WindowStartupLocation.CenterOwner; } else { messageBox.ShowInTaskbar = true; } messageBox.Owner = owner; messageBox.Title = caption; messageBox.MessageText = messageBoxText; messageBox.Type = type; switch (button) { case MessageBoxButton.OK: messageBox.ButtonCollection.Add(CreateButton(messageBox, "确定", FlatButtonSkinEnum.primary, MessageBoxResult.OK)); break; case MessageBoxButton.OKCancel: messageBox.ButtonCollection.Add(CreateButton(messageBox, "取消", FlatButtonSkinEnum.ghost, MessageBoxResult.Cancel)); messageBox.ButtonCollection.Add(CreateButton(messageBox, "确定", FlatButtonSkinEnum.primary, MessageBoxResult.OK)); break; case MessageBoxButton.YesNoCancel: messageBox.ButtonCollection.Add(CreateButton(messageBox, "取消", FlatButtonSkinEnum.Default, MessageBoxResult.Cancel)); messageBox.ButtonCollection.Add(CreateButton(messageBox, "否", FlatButtonSkinEnum.ghost, MessageBoxResult.No)); messageBox.ButtonCollection.Add(CreateButton(messageBox, "是", FlatButtonSkinEnum.primary, MessageBoxResult.Yes)); break; case MessageBoxButton.YesNo: messageBox.ButtonCollection.Add(CreateButton(messageBox, "否", FlatButtonSkinEnum.ghost, MessageBoxResult.No)); messageBox.ButtonCollection.Add(CreateButton(messageBox, "是", FlatButtonSkinEnum.primary, MessageBoxResult.Yes)); break; default: break; } //该行是关键代码,窗体显示后进入阻塞状态,直到窗体有返回值:即点击了某个按钮或者关闭了窗体 bool?result = messageBox.ShowDialog(); switch (button) { //break; case MessageBoxButton.OKCancel: { return(result == true ? MessageBoxResult.OK : result == false ? MessageBoxResult.Cancel : MessageBoxResult.None); } //break; case MessageBoxButton.YesNo: { return(result == true ? MessageBoxResult.Yes : MessageBoxResult.No); } //break; case MessageBoxButton.YesNoCancel: { return(result == true ? MessageBoxResult.Yes : result == false ? MessageBoxResult.No : MessageBoxResult.Cancel); } case MessageBoxButton.OK: default: { return(result == true ? MessageBoxResult.OK : MessageBoxResult.None); } } }