views:

53

answers:

1

In this example code, I'm trying to offset the Grid's Canvas position by the height of one of its rows. Does anyone see what I might be doing wrong? As you can see, I tried moving the binding lower in the xaml file, just in case the RowDefinitions needed to be defined first. Either way, it doesn't seem to matter because Canvas.Top is always 0.

<Canvas>
   <Grid Canvas.Top="{Binding ElementName=DetailsRow, Path=ActualHeight}">
      <Grid.RowDefinitions>
         <RowDefinition x:Name="NameRow" />
         <RowDefinition x:Name="DetailsRow" />
      </Grid.RowDefinitions>
      <Button Grid.Row="0">Button</Button>
      <Button Grid.Row="1">Button</Button>

      <!-- I expected this to maybe work, but no dice
      <Canvas.Top>
         <Binding ElementName="DetailsRow" Path="ActualHeight" />
      </Canvas.Top>
      -->

   </Grid>
</Canvas>
A: 

ActualHeight is not a dependency property so it's probably not triggering any kind of change notification. ActualHeight actually starts at 0 until the grid is measured so that could be one explanation. Unlike FrameworkElement, which does define ActualHeight as a dependency property, RowDefinition doesn't derive from FrameworkElement and just defines ActualHeight as a normal property with no change event.

I've actually thought about the fact that there should be a BindingMode.Polling option where the binding system would poll the source property at certain intervals. But unfortunately you may just be stuck doing it in code.

Josh Einstein
I didn't notice it wasn't a dependency property. Hm. Ok, I will keep looking, but I think you're probably right about needing to do it in code.
mos
@mos, Any luck?
Josh Einstein
I ended up putting a panel within that row, naming it, and then binding against its height. I get binding trace errors on start-up, but after the window is fully created everything seems to work out fine. If I can figure out how to remove those errors I'll post my solution here.
mos