开发者

How do I bind to a RowDefinition's height?

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>
      --&开发者_Go百科gt;

   </Grid>
</Canvas>


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜