Make my wpf application Full Screen (Cover taskbar

2019-01-23 05:14发布

I would like to make my application such that it can maximize to full screen means it hide the windows task bar and the title bar as well. And it should triggered by a button.

I am trying to develop the my application window like this. enter image description here

Add my code snippet below

 <controls:MetroWindow x:Class="EDUI.MainWindow"
            xmlns:controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:local="clr-namespace:EDiscoveryCore;assembly=EDiscoveryCore"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="eDi"  BorderBrush="SkyBlue" BorderThickness="2" Height="999" Width="1071" WindowState="Maximized" x:Name="MainWindows">

8条回答
干净又极端
2楼-- · 2019-01-23 05:42

You need to set the WindowStyle to none as well as WindowState to Maximized

<Window ...    
 WindowStyle="None"   
 WindowState="Maximized">
查看更多
对你真心纯属浪费
3楼-- · 2019-01-23 05:45

You need to set the ResizeMode to NoResize and WindowState to Maximized

  <Window ...    
    ResizeMode="NoResize" WindowState="Maximized">
查看更多
你好瞎i
4楼-- · 2019-01-23 05:49

Simply hook this event handler to the Loaded event of the form, works fine.
Do not apply this stuff in the constructor of the form (which won't work for me).

    private void aWindow_Loaded(object sender, RoutedEventArgs e)
    {
        MaxHeight = SystemParameters.FullPrimaryScreenHeight;
        MaxWidth = SystemParameters.FullPrimaryScreenWidth;
        Width = SystemParameters.FullPrimaryScreenWidth;
        Height = SystemParameters.FullPrimaryScreenHeight;
        WindowState = WindowState.Maximized;
        ResizeMode = ResizeMode.NoResize;
        Left = 0;
        Top = 0;
        Topmost = true;
        ShowInTaskbar = false;

        //throw new NotImplementedException();
    }
查看更多
Anthone
5楼-- · 2019-01-23 05:53

Try this:

<Window ShowTitleBar="False" IgnoreTaskbarOnMaximize="True">
查看更多
做个烂人
6楼-- · 2019-01-23 05:54

Step 1: Write class with static methods Hide() and Show() for taskbar

public class Taskbar
{
    [DllImport("user32.dll")]
    private static extern int FindWindow(string className, string windowText);
    [DllImport("user32.dll")]
    private static extern int ShowWindow(int hwnd, int command);

    private const int SW_HIDE = 0;
    private const int SW_SHOW = 1;

    protected static int Handle
    {
        get
        {
            return FindWindow("Shell_TrayWnd", "");
        }
    }

    private Taskbar()
    {
        // hide ctor
    }

    public static void Show()
    {
        ShowWindow(Handle, SW_SHOW);
    }

    public static void Hide()
    {
        ShowWindow(Handle, SW_HIDE);
    }
}

Step 2: Connect to window Closing event to get taskbar back when window will close with Alt+F4

private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
    Taskbar.Show();
}

Hide taskbar and show fullscreen:

Taskbar.Hide();
WindowStyle = WindowStyle.None;
WindowState = WindowState.Maximized;
ResizeMode = ResizeMode.NoResize;
Width = System.Windows.SystemParameters.PrimaryScreenWidth;
Height = System.Windows.SystemParameters.PrimaryScreenHeight;
Topmost = true;
Left = 0;
Top = 0;

Show taskbar and run in window

Taskbar.Show();
WindowStyle = WindowStyle.SingleBorderWindow;
WindowState = WindowState.Normal;
ResizeMode = ResizeMode.CanResize;
Width = System.Windows.SystemParameters.WorkArea.Width-100;
Height = System.Windows.SystemParameters.WorkArea.Height-100;
Topmost = false;
Left = 0;
Top = 0;

Tested on Windows 10 1703 (Creators Update)

enter image description here

查看更多
做自己的国王
7楼-- · 2019-01-23 05:57

I had this issue with the taskbar staying on top of my window. The current solution i use is setting the window as Topmost for a short time, then setting it back to false (i want my window to work nice with Alt+Tab)

private Timer t;
public void OnLoad()
    {
        var window = Application.Current.Windows.OfType<Window>().SingleOrDefault(x => x.IsActive);
        StartTopmostTimer(window);
    }

    private void StartTopmostTimer(Window window)
    {
        t = new Timer(o => SetTopMostFalse(window), null, 1000, Timeout.Infinite);
    }

    private void SetTopMostFalse(Window window)
    {
        Application.Current.Dispatcher.BeginInvoke(new Action(() =>
        {
            window.Topmost = false;
        }));
        t.Dispose();
    }

I also use this code to switch between full screen and window mode:

public void SwitchFullScreen()
    {
        var window = Application.Current.Windows.OfType<Window>().SingleOrDefault(x => x.IsActive);

        if (window != null)
        {
            if (window.WindowStyle == WindowStyle.None)
            {
                window.WindowStyle = WindowStyle.SingleBorderWindow;
                window.WindowState = state;
            }
            else
            {
                state = window.WindowState;
                window.WindowStyle = WindowStyle.None;
                window.WindowState = WindowState.Maximized;
                window.Topmost = true;
                StartTopmostTimer(window);
            }
        }
    }
查看更多
登录 后发表回答