mos*_*ald 3 wpf grid height xaml binding
在此示例代码中,我试图抵消Grid的Canvas通过其行的高度位置.有谁看到我可能做错了什么?正如您所看到的,我尝试在xaml文件中移动绑定较低的位置,以防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>
Run Code Online (Sandbox Code Playgroud)
ActualHeight不是依赖属性,因此它可能不会触发任何类型的更改通知.ActualHeight实际上从0开始直到测量网格,这可能是一个解释.与FrameworkElement定义ActualHeight为依赖属性的方法不同,RowDefinition它不是派生自FrameworkElement仅定义ActualHeight为没有更改事件的普通属性.
我实际上已经考虑过应该有一个BindingMode.Polling选项,绑定系统会以一定的间隔轮询源属性.但不幸的是,你可能只是被困在代码中.