如何绑定到一个RowDefinition的高度? [英] How do I bind to a RowDefinition's height?

查看:645
本文介绍了如何绑定到一个RowDefinition的高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这个例子中code,我试图抵消电网画布位置它的行中的一个的高度。有谁看到我可能是做错了?正如你所看到的,我试着移动绑定在XAML文件下,以防万一 RowDefinitions 我们首先需要界定。无论哪种方式,它似乎并不重要,因为 Canvas.Top 始终为0。

 <&帆布GT;
   <电网Canvas.Top ={绑定的ElementName = DetailsRow,路径=的ActualHeight}>
      < Grid.RowDefinitions>
         < RowDefinition X:NAME =NameRow/>
         < RowDefinition X:NAME =DetailsRow/>
      < /Grid.RowDefinitions>
      &所述;按钮Grid.Row =0>按钮和下; /按钮>
      &所述;按钮Grid.Row =1>按钮和下; /按钮>      <! - 我期望这也许工作,但没有骰子
      < Canvas.Top>
         <绑定的ElementName =DetailsRowPATH =的ActualHeight/>
      < /Canvas.Top>
       - >   < /网格和GT;
< /帆布>


解决方案

的ActualHeight 不是依赖属性,因此它可能不会触发任何形式的变更通知。 的ActualHeight 实际上是在0至电网进行测量,以便这可能是一个解释开始。不像 FrameworkElement的,这确实定义的ActualHeight 作为一个依赖属性, RowDefinition 不会从 FrameworkElement的,只是定义了的ActualHeight 作为一个没有变化的事件一个正常的属性。

其实我已经想到了一个事实,即应该有一个BindingMode.Polling选项,其中的绑定系统将在一定的时间间隔轮询源属性。但不幸的是,你可能只是被卡住做它在code。

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>

解决方案

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.

这篇关于如何绑定到一个RowDefinition的高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆