When the following XAML used, the window size is not 5000x5000, but some small window where the button is cropped.
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.
I guess the OS has provided the window with these values. It might be related to how Windows OS remembers the size of any window before it was last closed.*
The same way I suppose windows provided a default height and width to your window when none of the dimensions where specified.
I think the information you're looking for is buried in the documentation for FrameworkElement.Width
(link).
In addition to acceptable Double values, this property can also be Double.NaN. This is how you specify auto sizing behavior. In XAML you set the value to the string "Auto" (case insensitive) to enable the auto sizing behavior. Auto sizing behavior implies that the element will fill the width available to it. Note however that specific controls frequently supply default values in their default styles that will disable the auto sizing behavior unless it is specifically re-enabled. [my emphasis]
So, from this, I would expect that the width/height of the Window when there are no other constraints set (such as MaxWidth
, MinWidth
, Width
, etc.) is determined by the default style of a Window.
Edit:
Looks like it's more likely it comes from a function called by the Window
class itself that takes into account all the constraints plus the monitor size.
I can't find anything in MSDN that explicitly states what the size defaults are, but the Top
, Left
and WindowStartupLocation
property descriptions say that they default to the normal Win32 defaults if not specified. I think it's reasonable to assume that the Height
and Width
properties would do the same.
If you don't want this to happen for your window, then you must explicitly set either the Width
and Height
or the SizeToContent
property of the Window
element depending on your requirements. The explicit size you set on the Button
element will only have an effect on the Window
if Window.SizeToContent = True
.