应用程序初始化后最大化时,Style=None 的 WPF 窗口覆盖任务栏
我想要达到与 Windows Media Player 或基于浏览器的 Flash 播放器相同的效果,它们在最大化时占用整个空间(甚至任务栏都不可见)。
如果在 XAML 中将 WindowState
设置为 Maximized
并且将 WindowStyle
设置为 None
,则此方法可以正常工作,因此应用程序是在该状态下启动的。问题是我想在有边框的窗口中启动应用程序,当用户选择时,按照上面的指定最大化。在 StateChanged
处理程序中,我检查 Maximized
状态,如果是这种情况,我将 WindowStyle
设置为 None
。这具有最大化窗口但不覆盖任务栏的效果。以下代码将使此工作如我所愿,但它是一个黑客,我想清理它:
if (WindowState == WindowState.Maximized)
{
m_videoWindow.Maximize();
WindowStyle = WindowStyle.None;
//the following makes this work but I would like to clean it up
Hide();
Show();
}
编辑 This(从 2006 年开始,当时仍在 CTP 中)提到了这个问题,来自 MS 的某人表示他们希望改进下个版本支持全面屏,有这些改进吗?
I want to achieve the same effect as Windows Media Player or Browser based Flash players which take up the ENTIRE (not even the taskbar is visible) real estate when maximized.
This works fine if the WindowState
is set to Maximized
and the WindowStyle
is set to None
in XAML so the app is started in that state. Problem is I want to start the app in a bordered window and when the user chooses, maximize as specified above. In the StateChanged
handler I check for Maximized
state and if this is the case I set the WindowStyle
to None
. This has the effect of maximizing the window but NOT covering the taskbar. The following code will make this work as I want but its a hack and I'd like to clean it up:
if (WindowState == WindowState.Maximized)
{
m_videoWindow.Maximize();
WindowStyle = WindowStyle.None;
//the following makes this work but I would like to clean it up
Hide();
Show();
}
EDIT This (from 2006 when still in CTP) mentions the problem and someone from MS states they hope to improve full screen support in the next version, have these improvements been made?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
本文解释了这一切: 考虑任务栏最大化窗口(WindowStyle=None)。
还值得一看:自定义窗口WPF 中的 Chrome。
编辑:现在是新的 WPF Shell 集成库,它允许完全重新设计窗口镶边,而无需重新实现移动、调整大小等麻烦。
编辑 2015:Shell 集成库现已集成到 WPF 中,MS 已停用该代码
This article explains it all: Maximizing window (with WindowStyle=None) considering Taskbar.
Also worth checking out: Custom Window Chrome in WPF.
Edit: Now new, is the WPF Shell Integration Library that allows complete restyle of the window chrome without the headaches of reimplementing move, resizing, etc.
Edit 2015: Shell Integration Library is now integrated in WPF and MS retired the code
我发现我可以通过在创建窗口时(在 xaml 中)设置属性来最大化全屏(覆盖任务栏),但在创建后无法来回切换。经过一些实验,我发现属性设置的顺序似乎很重要:
请注意,WindowState 在设置器中排在最后。
I found I could maximize to full screen (covering the taskbar) by setting the properties when creating the window (in xaml), but was not able to switch back and forth after creation. After some experimenting, I found the order the properties are set seems to matter:
Note that WindowState comes last in the setter.
为了使其在我的 WPF/.NET 4.0 应用程序中正常工作,每当我进入或退出全屏模式时,我都会调用此函数:
此方法会出现闪烁,但进入全屏模式时似乎也存在相同的闪烁在 Chrome 上。 Internet Explorer 似乎采取了不同的方法。
To get this to properly work in my WPF/.NET 4.0 application I am calling this function whenever I enter or exit full screen mode:
There is a flicker associated with this method, but it seems the same flicker exists when going to full screen mode on Chrome. Internet Explorer seems to take a different approach.
我不知道这对你来说是否合适,但是你可以调整窗口大小,使其与工作区域(即,在大多数情况下,除了任务栏之外的所有屏幕)具有相同的大小,并将其定位在 0,0 (左上角):
WorkingArea 属性的确切定义(来自 MSDN)是:
获取显示器的工作区域。工作区域是显示器的桌面区域,不包括任务栏、停靠窗口和停靠工具栏。
希望有帮助
I don't know if this is ok for you, but you can resize the window to have the same size than the working area (that is, in most cases, all the screen except the taskbar) and locate it at 0,0 (top-left corner):
The exact definition for the WorkingArea property (from MSDN) is:
Gets the working area of the display. The working area is the desktop area of the display, excluding taskbars, docked windows, and docked tool bars.
Hope it helps