In the following example, there are two Grid
rows with height of 6*
and 4*
. The problem is that only after the user changes the the size of the window, the correct height of the rows is calculated.
This only happens when the SizeToContent
flag is set.
Any ideas why? How can I force the window to calculate the height automatically when it is loaded?
<Window x:Class="TestGridRow.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" SizeToContent="Height">
<Grid x:Name="grid">
<Grid.RowDefinitions>
<RowDefinition x:Name="row0" Height="6*"/>
<RowDefinition x:Name="row1" Height="4*"/>
</Grid.RowDefinitions>
<TextBox Grid.Row="0" x:Name="textBox" TextWrapping="Wrap"
HorizontalScrollBarVisibility="Auto" IsReadOnly="True" xml:space="preserve">
Hallo
Hallo
Hallo
</TextBox>
<TextBlock Background="Red" Grid.Row="1"/>
</Grid>