WPF: set the reference height to fill the height of the grid line

WPF grid management with 3 rows and 3 columns. Height of the Row is set to Auto. In the first two cells, I have two controls with dynamic heights. In the third cell, I have another control that I want to automatically adjust for stretching in the Grid cell. I tried VerticalAlignment="Stretch" , but it just sets the grid height equal to the control height. What are my options?

+6
source share
1 answer

Not sure which control you use in Cell 3, but most WPF controls automatically stretch to fit inside a Grid cell. The line height of your grid will be set by the height of the controls in cells 1 and 2.

If you use some kind of custom control where the default behavior for the height is different, you can set Height="Auto" .

If this does not work, you can bind the data to get the actual height of the control in cell 1 or 2. Set the Height property of your control in cell 3 to the following:

 Height="{Binding ActualHeight, ElementName=MyControlNameFromCell1, Mode=OneWay}" 

EDIT

Another way that can be more reliable is to bind data for row height. Therefore, instead of using "Auto" for line height, use the data binding shown above.

+7
source

All Articles