0
votes

I want to hide the taskbar when I maximize my application. It's starting in fullscreen mode with hidden taskbar (Defined in the MainWindow.xaml, defined with the following code):

WindowState="Maximized"
WindowStyle="None"

I want to be able to get the application back in normal windowed mode and then back to fullscreen with hidden taskbar.

When I click on the maximize button in the title bar, the application gets in fullscreen mode, but the taskbar stays visible. I already tried to set the ResizeMode to NoResize but it doesn't work for me.

Here is my code:

public MainWindow()
    {
        InitializeComponent();

        StateChanged += MainWindow_StateChanged;
    }

    private void MainWindow_StateChanged(object sender, EventArgs e)
    {
        var state = ((MainWindow)sender).WindowState;

        if(state == WindowState.Normal)
        {
            // When escaping
            ResizeMode = ResizeMode.CanResize;
            WindowStyle = WindowStyle.SingleBorderWindow;
        }
        else if(state == WindowState.Maximized)
        {
            // When maximizing
            ResizeMode = ResizeMode.NoResize;
            WindowStyle = WindowStyle.None;
            Topmost = true;
        }
    }

    private void Window_KeyDown(object sender, KeyEventArgs e)
    {
        if(e.Key == Key.Escape)
        {
            WindowState = WindowState.Normal;
        }
    }
1

1 Answers

0
votes

You should change the code as shown below:

Reference: this link

MaxHeight = SystemParameters.MaximizedPrimaryScreenHeight;
MaxWidth = SystemParameters.MaximizedPrimaryScreenWidth;

You can also try the win32 APIs mentioned at this thread.