如何数据绑定父 Stackpanel 的实际高度

How to Data Bind the ActualHeight of a Parent Stackpanel

我有一个带有 UserControl 的 Window。我想要完成的是绑定包含 UserControl 的 StackPanel 的 ActualHeight(stackpanel 没有固定大小),以便在 UserControl 中实现 WrapPanel 的正确行为。

我试过 Height="{Binding ElementName=MyStackPanel, Path=ActualHeight}"Height="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type StackPanel}}, Path=ActualHeight}" 但没有用。

我将 UserControl 放置在 Window 的 StackPanel 中的方式如下:

     <StackPanel x:Name="MyStackPanel" Orientation="Vertical">
         <!-- Wrap Panel / UserControl-->
         <local:WrapControl />
     </StackPanel>

如果有帮助主要Window是devexpressDXRibbonWindow.

好吧,看来 StackPanel 没有 "stretching" 的概念来占据所有可用的 space。

Grid 替换 StackPanel 效果完美。