tags:

views:

47

answers:

2

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>
+1  A: 

Debugging WHEN?

NAN is used during the layout phase from a control to say "any size you want" or "undefined". So any breakpoint during a specific phase may show NAN for various sizes.

Your controls does not define a specific size, so naturally it is "NAN". The final size is stored in other properties ;)

TomTom
I find it helps to explain WPF width and height as **desired** width and height
Rob Fonseca-Ensor
Well said ;) Will remember this next time.
TomTom
+2  A: 

You are looking for .RenderSize or .ActualSize

ima
Or `ActualSize`?
0xA3
Thx! Both give the same value, but ActualSize is easier to use as I can get ActualWidth and ActualHeight directly.
stiank81