.net – Window Size when SizeToContent is not specified

netwindowswpf

When the following XAML used, the window size is not 5000×5000, but some small window where the button is cropped.

<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" >
    <Button Width="5000" Height="5000">XXX</Button>
</Window>

From what I can tell, size I did not specify the SizeToContent attribute, the default is "Manual", so it will use *size of a window is determined by other properties, including Width, Height, MaxWidth, MaxHeight, MinWidth, and MinHeight. * From the WPF Windows Overview, it seems those other properties are FrameworkElement::MinHeight/Width, and FrameworkElement::MaxHeight. But since the default for the Mins are 0, the Maxs are Infinity and the Width/Height is Nan….what's going on? Where is WPF getting the window size?

Any pointers to the right direction would be appreciated.

Best Answer

If the width and height are not specified WPF uses 60% of the width of you primary screen (where the windows is actually displayed) and 60% of its height. This is done by the Application singleton where all Windows ultimately register themselfes.

Related Topic