Это мой c# код:
double height = grid.ActualHeight;
double newHeight = height - rectangle.ActualHeight;
topRectangle.Height = newHeight;
label.Content = "height: " + height + "\nNew Height: " + newHeight;
, а файл xaml таков:
<Grid x:Name="grid" Height="Auto" Width="Auto">
<Rectangle x:Name="rectangle" Fill="#FF181818" HorizontalAlignment="Left" Height="222" Margin="0,0,-0.333,0" Stroke="#FF181818" VerticalAlignment="Bottom" Width="{Binding ActualWidth, ElementName=grid}"/>
<Rectangle x:Name="topRectangle" Fill="#FF181818" HorizontalAlignment="Left" Height="285" Margin="0,0,0,221.667" Stroke="#FF181818" VerticalAlignment="Bottom" Width="190"/>
<Label x:Name="label" Content="Label" HorizontalAlignment="Left" Margin="306,99,0,0" VerticalAlignment="Top" Foreground="White"/>
</Grid>
Текст метки в момент запуска такой:
height: 0
New Height: 0
но для большего количества я стараюсь, это всегда дает 0, а topRectangle не отображается из-за высоты 0. Я попытался установить topRectangle.Height вместо ActualHeight, и это было:
высота: NaN
Фактическая высота: NaN
, если это не ясно в код, высота сетки и прямоугольника НЕ равна 0
Есть ответы?