c# - 删除扩展 WPF 工具包样式中的关闭按钮

标签 c# wpf wpf-controls wpftoolkit

我在这里使用扩展 WPF 工具包消息框:http://wpftoolkit.codeplex.com/wikipage?title=MessageBox&referringTitle=Home 但我不确定如何从 MessageBox 类型中删除关闭按钮 - 我根本不希望用户关闭 MessageBox。

感谢您的帮助!

编辑:如果我在这样的代码中创建样式 setter :

System.Windows.Style style = new Style();
style.Setters.Add(new Setter(Xceed.Wpf.Toolkit.MessageBox.CloseButtonVisibilityProperty, 
Visibility.Hidden));

messageBox.Style = style;

我遇到异常:

Xceed.Wpf.Toolkit.dll 中发生“System.InvalidOperationException”类型的异常,但未在用户代码中处理

附加信息:MessageBox 上的关闭按钮始终可见。

最佳答案

正如 @Giallo 所说,尝试设置 Visibility 属性会引发异常。

为了隐藏关闭按钮,您需要将按钮的 IsEnabled 属性设置为 false,并将 Opacity 属性设置为 0.0,如下所示:

Style closeButtonStyle = new Style(typeof(Button));
closeButtonStyle.Setters.Add(new Setter(UIElement.IsEnabledProperty, false));
closeButtonStyle.Setters.Add(new Setter(UIElement.OpacityProperty, 0.0));

Style msgBoxStyle = new Style(typeof(MessageBox));        
msgBoxStyle.Setters.Add(new Setter(WindowControl.CloseButtonStyleProperty, closeButtonStyle));

然后显示您的消息框并引用您刚刚创建的 MessageBox 样式:

MessageBoxResult result = MessageBox.Show(
    "Message Text", 
    "MessageBox Caption", 
    MessageBoxButton.OK, 
    MessageBoxImage.None, 
    MessageBoxResult.None, 
    msgBoxStyle);

关于c# - 删除扩展 WPF 工具包样式中的关闭按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30762077/

相关文章:

c# - 中继访问被拒绝 5.7.1

c# - WPF 子窗口 - Windows 7 任务栏

c# - 我如何在 WPF 中读取 base64 图像?

wpf - 获取 WPF 元素的真实视觉边界框?

wpf - 在 WPF 中,如何为模板中设计的 FrameworkElement 添加 EventHandler?

WPF ObservableCollection 编辑模式

c# 未授权异常

c# - 如何使用 C# 隐藏/显示进程?

c# - 为什么 Calli 比委托(delegate)调用更快?

WPF 文本 block 动画