[SOLVED] WPF doesn’t want to go full screen


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

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

<Window x:Class="LeagueOfTeamsUI.Views.GameWindow"
    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)

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?


Your problem is the SizeToContent property. You set it to SizeToContent="WidthAndHeight" which means that:

// Automatically resize height and width relative to content

this.SizeToContent = SizeToContent.WidthAndHeight;

While your window maximizes the content size does not change, and the window size will stay the same.



Remove that property and it should work.

This Question was asked in StackOverflow by Павел Нестеренко and Answered by Nawed Nabi Zada It 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?