Borderless Window Not Maximizing Correctly

By design (for what reason, I don't know), when you have WindowStyle="None" and you maximize the window, it will extend beyond the actual edge of the screen by several pixels on all sides.

In your code, you are restricting the actual size of the window to the exact dimensions of the work area. Since the maximizing of the window still puts the top-left corner of the window those several pixels to the left and above the top-left corner of the work area, the visible portion of the window is necessarily less than the entire width of the work area, hence the exposed area on the right and the bottom.

As noted by commenter Evk, by removing the size restriction on the window (which you can do only when the window is maximized, if you like), the window can expand to the full size WPF wants, ensuring full coverage of the work area.

In your follow-up comment, it's not clear whether you actually want the taskbar to be covered or not. In either case, you may find these links useful to address your specific needs in that regard:
Maximize window with WindowState Problem (application will hide windows taskbar)
Maximizing window (with WindowStyle=None) considering Taskbar

Alternatively, you could still set the size restriction, but take into account the additional pixel margin that WPF insists on when the window is maximized, setting the dimensions larger than needed so that there is no exposed area.

For what it's worth, here is a simplified code example that focuses solely on the specific behavior here:

<Window x:Class="TestSO39578992MaximizeBorderless.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:p="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:TestSO39578992MaximizeBorderless"
        mc:Ignorable="d" Background="Yellow" 
        WindowStyle="None" AllowsTransparency="True"
        Title="MainWindow" Height="350" Width="525">
  <Window.Style>
    <p:Style TargetType="Window">
      <Setter Property="WindowState" Value="Normal"/>
      <!-- Uncomment "Topmost" setters to experiment with its effect on the task bar visibility -->
      <!--<Setter Property="Topmost" Value="False"/>-->
      <p:Style.Triggers>
        <DataTrigger Binding="{Binding IsChecked, ElementName=checkBox1}" Value="True">
          <Setter Property="WindowState" Value="Maximized"/>
          <!--<Setter Property="Topmost" Value="True"/>-->
        </DataTrigger>
      </p:Style.Triggers>
    </p:Style>
  </Window.Style>
  <!-- set the margin here, to account for the extra space WPF is adding -->
  <!-- <Grid Margin="6"> -->
  <Grid>
    <Grid.ColumnDefinitions>
      <ColumnDefinition/>
      <ColumnDefinition/>
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
      <RowDefinition/>
      <RowDefinition/>
    </Grid.RowDefinitions>
    <CheckBox x:Name="checkBox1" Content="Maximized" HorizontalAlignment="Left" VerticalAlignment="Top"/>
    <TextBlock Text="Upper Right" Grid.Column="1" HorizontalAlignment="Right" VerticalAlignment="Top"/>
    <TextBlock Text="Lower Left" Grid.Row="1" HorizontalAlignment="Left" VerticalAlignment="Bottom"/>
    <TextBlock Text="Lower Right" Grid.Row="1" HorizontalAlignment="Right" VerticalAlignment="Bottom" Grid.Column="1"/>
  </Grid>
</Window>

And of course:

public partial class MainWindow : Window
{
    public MainWindow()
    {
        this.MaxHeight = SystemParameters.WorkArea.Height;
        this.MaxWidth = SystemParameters.WorkArea.Width;

        // Compensate for the extra space WPF adds by increasing the max width and height here
        //this.MaxHeight = SystemParameters.WorkArea.Height + 12;
        //this.MaxWidth = SystemParameters.WorkArea.Width + 12;

        InitializeComponent();
    }
}

I've included TextBlock elements in all four corners to make it easier to see how the window size is affected by the various property values.


I had the same issue, but by turning of window resizing with

Me.ResizeMode = ResizeMode.NoResize 

upon changing the window state to maximised, removes the issue

Tags:

C#

Wpf

Xaml