When the following XAML used, the window size is not 5000x5000, but some small window where the button is cropped.
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.