Get RowDefinition Height Programmatically

I have this XAML:

<Grid Background="LightYellow" Height="150" Width="150">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
</Grid>

And I'm trying to get the height of the second row as follows:

height = grid.RowDefinitions[1].Height.Value;

But I get 1. I tried ActualSize, and it doesn't work either (returns 0). How can I get the row height?

+3
source share
2 answers

Firstly, the reason that Height.Value returns 1 is because Height is GridLength, with GridUnitType of Star. 1 - from the proportional size of the star (for example, Height = "2 *", Height = "3 *", etc.). That is, you cannot read GridLength.Value separately: you must read it in combination with GridUnitType.

. WPF ActualHeight , , . RowDefinition.ActualHeight docs:

, ActualWidth ColumnDefinition ActualHeight RowDefinition , .

, ActualHeight , WPF Measure, 0 .

, ActualHeight: WPF (- ), SizeChanged OnRenderSizeChanged. , , ( ) InvalidateVisual ( - , OnRender).

+3

?

, .

0

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


All Articles