I looked at this question and found something very strange: it seems that the line height is not calculated correctly in some cases involving Grid.RowSpan .
Here's a simple Grid drawing I'm testing with:
---------------
| 1 | |
-------- | 3 |
| 2 | |
---------------
| 4 |
---------------
And here is a sample code for this grid that demonstrates the problem:
<Grid ShowGridLines="True"> <Grid.ColumnDefinitions> <ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> <RowDefinition Height="*"/> </Grid.RowDefinitions> <StackPanel Grid.Column="0" Grid.Row="0" Grid.RowSpan="2" Background="Red"> <Label Content="CELL 1 A"/> <Label Content="CELL 1 B"/> <Label Content="CELL 1 C"/> </StackPanel> <Grid Grid.Column="0" Grid.Row="2" Background="CornflowerBlue"> <Label Content="CELL 2 D"/> </Grid> <StackPanel Grid.Column="1" Grid.Row="0" Grid.RowSpan="3" Background="Yellow"> <Label Content="CELL 3 A"/> <Label Content="CELL 3 B"/> <Label Content="CELL 3 C"/> <Label Content="CELL 3 D"/> </StackPanel> <Grid Grid.Column="0" Grid.Row="3" Grid.ColumnSpan="2" Background="Green"> <Label Content="CELL 4"/> </Grid> </Grid>
The end result is the height of the third row (cells # 2 and # 3), in which there is a lot of extra space:

If I adjust the Grid.RowSpan of the 1st and 3rd cells to +/- 1 and adjust the Grid.Row for the second and fourth cells to +/- 1 to account for the extra row, I get this (correctly) result:

I also get the correct results if I remove enough elements from cell # 3 so that it can display on a single line, for example:

And strangely enough, the removal of some objects leads to the fact that only some additional space is applied

I talked about the number of elements in cells # 1 and # 3 and the number of rows, but I canβt understand that there is no convincing pattern to explain this behavior.
What exactly does WPF do behind the scenes when rendering this grid to cause extra space to Grid.RowSpan with Grid.RowSpan on cell # 3?
wpf grid
Rachel
source share