我基本上想有我的WPF窗口在全屏模式下,当按下F11键或在窗口被按下右上角的最大化按钮去了。
I basically want to have my WPF window to go in full screen mode, when F11 is pressed or the maximize button in the right top corner of the window is pressed.
虽然下面的作品就像一个魅力为按F11:
While the following works like a charm for pressing F11:
private void Window_KeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.F11) { WindowStyle = WindowStyle.None; WindowState = WindowState.Maximized; ResizeMode = ResizeMode.NoResize; } }这将仍显示在Windows任务栏上(与Windows测试7):
This will still displays the Windows taskbar (tested with Windows 7):
protected override void OnStateChanged(EventArgs e) { if (WindowState == WindowState.Maximized) { WindowStyle = WindowStyle.None; WindowState = WindowState.Maximized; ResizeMode = ResizeMode.NoResize; } base.OnStateChanged(e); }
我缺少的是在这里吗?或者,我可以做到这一点更显优雅?
What am I missing here? Or can I do it even more elegant?
推荐答案WPF似乎是作出有关是否要全屏或尊重的决定基于所述WindowStyle在最大化的时间的任务栏。因此缺憾而有效的解决方案是将切换窗口回非最大化,设置WindowStyle,然后再次设置窗口回最大化
WPF seems to be making the decision about whether to go full-screen or respect the taskbar based on the WindowStyle at the time of maximisation. So a kludgy but effective solution is to switch the window back to non-maximised, set the WindowStyle, and then set the window back to maximised again:
private bool _inStateChange; protected override void OnStateChanged(EventArgs e) { if (WindowState == WindowState.Maximized && !_inStateChange) { _inStateChange = true; WindowState = WindowState.Normal; WindowStyle = WindowStyle.None; WindowState = WindowState.Maximized; ResizeMode = ResizeMode.NoResize; _inStateChange = false; } base.OnStateChanged(e); }
虽然代码显然是丑陋的,过渡到正常,然后返回到最大化似乎并没有让用户体验更差。在我的显示,我注意到无论是F11代码和杂牌最大化,而不是对杂牌最大化明显恶化闪烁。但是你的里程可能会有所不同!
Although the code is obviously ugly, the transition to Normal and then back to Maximized doesn't seem to make the user experience any worse. On my display, I noticed flicker with both the F11 code and the kludge maximise, but not noticeably worse on the kludge maximise. But your mileage may vary!
更多推荐
WPF的最大化全屏
发布评论