Why are my WPF window sizes defaulting to be huge Why are my WPF window sizes defaulting to be huge wpf wpf

Why are my WPF window sizes defaulting to be huge


If you create a <Window/> with this code:

<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" />

Then when you run that from Visual Studio it will display a window the same size as the one you put in your question. So this isn't anything you explicitly did.

What you've encountered is the default computed size of a WPF Window. For different results, specify a SizeToContent parameter on the Window, as paxdiablo pointed out, or explicitly set the size of your window with the MinHeight, MaxHeight, Height, MinWidth, MaxWidth, and/or Width properties.


Why don't you just add a:

Height="296" Width="634"

to the Window definition? I'm not sure where the default size comes from but I've set specific sizes on my windows to get around this. Then I dynamically resize in the application startup code.

I'm hoping that WPF will have a pack-like feature where it recursively sets controls based on the preferred sizes of the sub-controls (Swing and wxPython both had this feature) so you may want to go looking for that.


Actually, a bit of searching has turned up the Window.SizeToContent property which may be what you're looking for. Its default is Manual but, if you set it to one of the other values (Width, Height or WidthAndHeight), you may see a better presentation.

In fact, I just nicked over to the Windows laptop and entered:

SizeToContent="WidthAndHeight"

into the Window definition and it looks perfectly sized. So, I'd suggest giving that a try and seeing if it fixes (or at least works around) your problem.


In design you are seeing small because you have blend design properties for the window.

d:DesignHeight="296" d:DesignWidth="634"

Since Grid is a dynamic layout it will be stretch to the window's width & height. To restrict you window size you need to mention Height & Width properties to the window.