是否可以显示标题栏中没有图标的 wpf 窗口?
众所周知,如果 wpf 窗口的图标未定义,则显示默认图标。我想显示一个标题栏中没有任何图标的窗口。我意识到我可以使用空白图像,但这会导致标题栏中的文本向右偏移。
有谁知道有什么方法可以彻底删除图标吗?
(我尝试搜索类似的问题,但找不到任何内容。)
As we all know, if the icon for a wpf window is undefined then the default icon is displayed. I want to display a window without any icon in the title bar. I realise that I could use a blank image, however this would cause the text in the title bar to be offset to the right.
Does anyone know of a way to completely remove the icon?
(I tried searching for a similar question but couldn't find anything.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
很简单,将此代码添加到您的窗口中:
Simple, add this code to your window:
虽然这不完全是一个正确的解决方案,但您可以尝试以下操作之一:
将 WindowStyle-Property 设置为 ToolWindow 将使图标消失,但标题栏(显然)会变小。
为整个窗口编写一个 ControlTemplate。根据窗口是否必须看起来像“真实”窗口,尝试在模板中重新创建默认样式需要付出很大的努力。
While not exactly a proper solution, you could try one of the following things:
Setting the WindowStyle-Property to ToolWindow will make the Icon disappear, but the title bar (obviously) will be smaller.
Write a ControlTemplate for the whole Window. Depending on if the Window has to look like a "real" Window, there'd be much effort into trying to recreate the default Style in the Template.
我知道这个问题已经得到解答,但是 Dan Rigsby 的博客< /a> 有一篇文章展示了如何在不隐藏最小化/最大化框的情况下执行此操作。
我发现这让我很沮丧,因为我正在使用这些文章(此处 和 此处 但它一直隐藏所有按钮系统菜单被隐藏,以帮助我创建这个帮助程序,如上所示,在
OnSourceInitialized
中调用它。I know this is answered, however Dan Rigsby's blog has an article that shows how to do this without hiding the minimize/maximize boxes.
I found this was frustrating me as I was using the articles (here and here but it kept hiding all the buttons when the sysmenu was hidden, to help I created this helper which as shown above call in
OnSourceInitialized
.不,这似乎不可能。引用 图标属性 的文档(强调我的):
因此,显然完全透明的图标似乎是您最好的选择。或者也许可以通过使用 Windows API 函数在窗口上设置适当的样式来解决所有这些问题。但这可能会干扰 WPF 的窗口管理。
No, this doesn't seem to be possible. Quoting from the documentation of the Icon property (emphasis mine):
So, apparently a completely transparent icon seems to be your best bet here. Or perhaps hack around all this by using Windows API functions to set the appropriate style on the window. But this may interfere with WPF's window management.
您可以使用空的 png 图像并将其转换为图标并将其设置为您的窗口的图标!
You can use an empty png image and convert it to icon and set it as icon for your window!!!
将以下代码添加到
Window
的主类中以删除最大化和最小化按钮,并隐藏图标。Add the following code to the main class of your
Window
to remove the maximize and minimize buttons, and hide the icon.我的第一个建议是不要这样做。在 WinForms 中,您可以使用 formborderstyles 类型来创建没有图标的对话框,但这只是因为这是 Windows 标准。只有具有这些特定边框类型的表单才不应有图标;这是用户所期望的。
My first suggestion would be don't do it. In WinForms you can use types of formborderstyles to create a dialog box that has no icon, but only because that is a Windows standard. Only forms with those specific border types should have no icon; it's what users expect.