For developers who are from WPF to UWP/WinUI.
In principle, it requires that window's size be dependent on its content. While for UWP and WinUI, content will adjust themselves by window's size.
This makes sense because window is not the only possible host of Window's content.
For example, the following code will make a window getting smaller and smaller, because it forms a circular dependency.
private void ContentGrid_SizeChanged(object sender, SizeChangedEventArgs e)
{
this.Width = e.NewSize.Width;
this.Height = e.NewSize.Height;
}
If you really want to resize to its content, the circle must be cut to prevent infinite resizing. To be specific, you must either
- fix your content's size, or
- use some other strategy to reach a compromise between window and its content
But in either way, the ui will become much less flexible and error prone to culture change.