How to adjust window height for content?

I have a simple window.
In this window, I have a grid with several rows, the height of which I adjust dynamically.
Now I want to make Window.Height = sum of Grids Rows.
It seems that the problem is that the grid itself fills the entire window (this is normal), but in this grid the area occupied by the rows occupies an empty space.
What should I do?

For example, I have a witch’s height = 100 and 200, and the whole grid has a height of 500, but should have 300.

+4
source share
2 answers
 <Window ... SizeToContent="WidthAndHeight"> <Grid> ... </Grid> </Window> 

SizeToContent is the property you want to set. I use it all the time, it's great.

+8
source

Set the Window.SizeToContent property to WidthAndHeight.

+2
source

Source: https://habr.com/ru/post/1343831/


All Articles