WPF Window with Style=None cover taskbar when Maximised after app initialization

那年仲夏 提交于 2019-12-30 02:43:07

问题


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?


回答1:


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




回答2:


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.




回答3:


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.




回答4:


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



来源:https://stackoverflow.com/questions/1464908/wpf-window-with-style-none-cover-taskbar-when-maximised-after-app-initialization

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!