应用程序初始化后最大化时,Style=None 的 WPF 窗口覆盖任务栏

发布于 2024-08-05 10:39:22 字数 898 浏览 2 评论 0原文

我想要达到与 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

安稳善良 2024-08-12 10:39:22

本文解释了这一切: 考虑任务栏最大化窗口(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

苦行僧 2024-08-12 10:39:22

我发现我可以通过在创建窗口时(在 xaml 中)设置属性来最大化全屏(覆盖任务栏),但在创建后无法来回切换。经过一些实验,我发现属性设置的顺序似乎很重要:

public bool IsFullscreen
{
    get 
    {
        return WindowState == System.Windows.WindowState.Maximized
            && ResizeMode == System.Windows.ResizeMode.NoResize
            && WindowStyle== System.Windows.WindowStyle.None;
    }
    set
    {
        if ( value )
        {
            ResizeMode = System.Windows.ResizeMode.NoResize;
            WindowStyle = System.Windows.WindowStyle.None;
            WindowState = System.Windows.WindowState.Maximized;
        }
        else
        {
            ResizeMode = System.Windows.ResizeMode.CanResize;
            WindowStyle = System.Windows.WindowStyle.SingleBorderWindow;
            WindowState = System.Windows.WindowState.Normal;            
        }
    }
}

请注意,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:

public bool IsFullscreen
{
    get 
    {
        return WindowState == System.Windows.WindowState.Maximized
            && ResizeMode == System.Windows.ResizeMode.NoResize
            && WindowStyle== System.Windows.WindowStyle.None;
    }
    set
    {
        if ( value )
        {
            ResizeMode = System.Windows.ResizeMode.NoResize;
            WindowStyle = System.Windows.WindowStyle.None;
            WindowState = System.Windows.WindowState.Maximized;
        }
        else
        {
            ResizeMode = System.Windows.ResizeMode.CanResize;
            WindowStyle = System.Windows.WindowStyle.SingleBorderWindow;
            WindowState = System.Windows.WindowState.Normal;            
        }
    }
}

Note that WindowState comes last in the setter.

迟月 2024-08-12 10:39:22

为了使其在我的 WPF/.NET 4.0 应用程序中正常工作,每当我进入或退出全屏模式时,我都会调用此函数:

private static void RefreshWindowVisibility(Window window)
        {
            if (window.OriginalWindowState == WindowState.Maximized)
            {
                window.Hide();
                window.Show();
                window.BringIntoView();
            }
        }

此方法会出现闪烁,但进入全屏模式时似乎也存在相同的闪烁在 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:

private static void RefreshWindowVisibility(Window window)
        {
            if (window.OriginalWindowState == WindowState.Maximized)
            {
                window.Hide();
                window.Show();
                window.BringIntoView();
            }
        }

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.

盛夏已如深秋| 2024-08-12 10:39:22

我不知道这对你来说是否合适,但是你可以调整窗口大小,使其与工作区域(即,在大多数情况下,除了任务栏之外的所有屏幕)具有相同的大小,并将其定位在 0,0 (左上角):

Width = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width; 
Height = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height; 
Left = 0; 
Top = 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):

Width = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width; 
Height = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height; 
Left = 0; 
Top = 0;

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文