0
votes

My application starts with WindowStyle set to None, ResizeMode set to NoResize and WindowState to Maximized. I send Windows (Windows 10) into sleep mode and when I wake from sleep mode, the application resizes so the Windows Taskbar is visible. Before being put into sleep mode, the Taskbar is hidden by the application because the WindowStyle is None.

How can I keep the Taskbar behind my application? I've tried catching the SizeChanged event and re-maximizing it, or changing the style to something else and back to None and nothing has worked.

This can be demonstrated with a simple application with a main window like this:

<Window x:Class="MaximizedNoChrome.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:MaximizedNoChrome"
        mc:Ignorable="d"
        Title="MainWindow" WindowState="Maximized" WindowStyle="None" Background="IndianRed">
    <Grid>

    </Grid>
</Window>

Before Sleep enter image description here After Sleep enter image description here

1
Works fine hereJim
Interesting. It must be a Windows setting. I have a brand new ASUS laptop and it does this every time. Does anybody else experience this?Matt Becker
Does the TaskBar hide after you click on the application?XAMlMAX
No it doesn't. I tried using Alt+Tab or Windows+Tab and those don't hide it either.Matt Becker
I am able to get the app to be on top of the TaskBar again by cascading the windows and then undo-ing it. I can also do it by using Show windows side by side, but I need to do this in code.Matt Becker

1 Answers

0
votes

I don't know if this is the best answer, but it's one way to get this problem to go away. I subscribe to the PowerModeChanged system event to capture the resume event and then I collapse/show and Normal/Maximize the window in the Activated event.

If you have a better solution, please let me know.

SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged;

...

private void SystemEvents_PowerModeChanged(object sender, PowerModeChangedEventArgs e)
{
    if (e.Mode == PowerModes.Resume)
    {
        _resumed = true;
    }
}

...

private void Window_Activated(object sender, EventArgs e)
{
    if (_resumed)
    {
        Visibility = Visibility.Collapsed;
        Visibility = Visibility.Visible;
        WindowState = WindowState.Normal;
        WindowState = WindowState.Maximized;
        _resumed = false;
    }
}