【问题标题】:Does anyone know how to get the WPF MessageBox to look better (like the Windows Forms equivelant)? [duplicate]有谁知道如何让 WPF MessageBox 看起来更好(如 Windows 窗体等价物)? [复制]
【发布时间】:2019-04-30 23:06:31
【问题描述】:

可能重复:
WPF MessageBox window style

由于某种原因,WPF 附带的 MessageBox 禁用了视觉样式,我找不到打开它们的方法,在 Windows 窗体中,只需在程序开始时调用 Application.EnableVisualStyles() .

为了了解我在说什么,这里有两个例子:

System.Windows.Forms.Application.EnableVisualStyles();
System.Windows.Forms.MessageBox.Show(
    "Windows Forms Dialog",
    "Message Box Test",
    System.Windows.Forms.MessageBoxButtons.OK,
    System.Windows.Forms.MessageBoxIcon.Asterisk);

System.Windows.MessageBox.Show(
    "WPF Dialog",
    "Message Box Test",
    System.Windows.MessageBoxButton.OK,
    System.Windows.MessageBoxImage.Asterisk);

调用 System.Windows.Forms.Application.EnableVisualStyles() 对 WPF 没有影响。

Extended WPF Toolkit 有一个很好的主题实现,但我正在寻找一种方法来创建与用户正在运行的操作系统相匹配的消息框。如果您希望在每个操作系统上都使用相同的样式,那么 EWPFT 实现非常棒。

【问题讨论】:

  • 我必须道歉,是的,这是重复的,不知道为什么我没有在搜索结果中看到它。
  • 没问题。我之前遇到过这个问题,所以我知道要搜索“wpf messagebox manifest”。

标签: .net wpf


【解决方案1】:

不要再使用 MessageBox,改用 P/Invoke TaskDialogIndirect - 它看起来比这两者都好,并且有更多选项(例如,具有任意按钮文本)

【讨论】:

  • 感谢 Paul,看起来是一个可行的解决方案,还可以提供额外的功能。
  • @David 停止使用 XP。漂亮吗?
  • @paul 是的,我已经停止了,但我的客户继续使用它!如果你想卖软件,那么你必须支持xp。
  • @Paul,这还不如“它在 IE 6 上不起作用”那么糟糕 :)
  • @David,您始终可以将任务对话框包装在操作系统检查中。这就是 MS 在 VistaBridge SDK 示例中所做的:msdn.microsoft.com/en-us/library/ms756482(v=vs.90).aspx
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2010-09-30
  • 1970-01-01
  • 1970-01-01
  • 2010-09-07
  • 2013-08-09
  • 2014-08-26
  • 1970-01-01
相关资源
最近更新 更多