Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can my controls size be NaN when it is actually shown?

Tags:

.net

wpf

grid

I have a Grid which contains an Image in one of its columns. The image itself does not have any Width or Height set, but its size is correctly controlled through the ColumnDefinition set. From this I would assume that the image controller actually has a Width and Height set, but when I try to bind another element to its Width and Height it doesn't work. When debugging it turns out that the value of Image.Height and Image.Width are NaN. Why?

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="350"></ColumnDefinition>
        <ColumnDefinition Width="*"></ColumnDefinition>
        <ColumnDefinition Width="10"></ColumnDefinition>
        <ColumnDefinition Width="*"></ColumnDefinition>
    </Grid.ColumnDefinitions>

    <Grid Grid.Column="0">
        <Image x:Name="_image" Source="image.jpg"></Image>
    </Grid>

 </Grid>
like image 711
stiank81 Avatar asked Jan 21 '26 18:01

stiank81


1 Answers

You are looking for .RenderSize or .ActualSize

like image 59
ima Avatar answered Jan 23 '26 21:01

ima



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!