wpf - 如何绑定(bind)到 RowDefinition 的高度?

标签 wpf xaml binding grid height

在此示例代码中,我试图将 GridCanvas 位置偏移其行之一的高度。有谁看到我可能做错了什么?如您所见,我尝试在 xaml 文件中将绑定(bind)移到较低位置,以防需要先定义 RowDefinitions。无论哪种方式,这似乎都无关紧要,因为 Canvas.Top 始终为 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 不是依赖属性,因此它可能不会触发任何类型的更改通知。 ActualHeight 实际上从 0 开始,直到测量网格,这可能是一种解释。与将 ActualHeight 定义为依赖属性的 FrameworkElement 不同,RowDefinition 不是从 FrameworkElement 派生的,而只是定义ActualHeight 作为没有更改事件的普通属性。

我实际上已经考虑过这样一个事实,即应该有一个 BindingMode.Polling 选项,在该选项中绑定(bind)系统会以特定间隔轮询源属性。但不幸的是,您可能只是被困在代码中。

关于wpf - 如何绑定(bind)到 RowDefinition 的高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2415091/

相关文章:

wpf - 如果我的应用程序未设置 StartupUri,则 App.xaml 文件不会被解析?

c# - 显示/隐藏 Mahapps 弹出控件

C#/winforms : how to best bind a propertygrid and a System. 数据.数据行

c# - 如何在 wpf 用户控件中收听 INotifyCollectionChanged

wpf - 将插入符号/光标位置设置为字符串值 WPF 文本框的末尾

wpf - 在嵌套样式中设置 RenderTransform

.net - 尝试以 xaml xamarin 形式进行本地化

javascript - 失败 : Cannot read property 'bind' of undefined Protractor

c# - WPF BitmapSource 图像源

wpf - 使用 Process.Start() 启动后等待 WPF 应用程序加载