WPF doesn’t want to go full screen

Issue

This Content is from Stack Overflow. Question asked by Павел Нестеренко

Hello!
I was making my own minimize and fullscreen buttons but ran into a problem.
I have some window:

<Window x:Class="LeagueOfTeamsUI.Views.GameWindow"
    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:LeagueOfTeamsUI.Views"
    mc:Ignorable="d"
    
    x:Name="GameMainWindow" Title="GameWindow" AllowDrop="True"
    MinWidth="1440" MinHeight="810" WindowStyle="None"
    
    MouseLeftButtonDown="GameMainWindow_MouseLeftButtonDown"  Background="{x:Null}"
    SizeToContent="WidthAndHeight" AllowsTransparency="True">

And have toggle button, to make window fullscreen:

private void CheckedFullScreenButton_Click(object sender, RoutedEventArgs e)
    {
        GameMainWindow.WindowState = WindowState.Maximized;
    }
private void UncheckedFullScreenButton_Click(object sender, RoutedEventArgs e)
    {
        GameMainWindow.WindowState = WindowState.Normal;
    }
private void GameMainWindow_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
        this.DragMove();
    }

But when I use this button – the window stays the same size. It only sticks to the top left corner.

I found that if I manually drag the window to the edge of the screen once (on Win10 this stretches the window to half the screen), then nothing changes and the window also sticks to the corner. But if you repeat this action, the window is stretched to half the screen. After that, the fullscreen button works correctly while the app is running.

Please show me what I did wrong?



Solution

This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?