我发现ActualWidth
最有用的,当我想绑定一个元素的宽度或高度另一个。
在这个简单的例子中,我有两个并排排列的按钮,下面的注释被限制为包含两个按钮的StackPanel的宽度。
<StackPanel>
<StackPanel Margin="0,12,0,0" Orientation="Horizontal" Name="buttonPanel" HorizontalAlignment="Left" >
<Button Content="Yes - Arm the missile" FontWeight="Bold" HorizontalAlignment="Left"/>
<Button Content="No - Save the world" HorizontalAlignment="Left" Margin="7,0,0,0"/>
</StackPanel>
<TextBlock Text="Please choose whether you want to arm the missile and kill everybody, or save the world by deactivating the missile."
Width="{Binding Path=ActualWidth,ElementName=buttonPanel}" Margin="0,5,0,0" HorizontalAlignment="Left" TextWrapping="Wrap"/>
</StackPanel>
它实际上是布局大小而不是渲染大小。 – chuckj 2009-03-04 09:40:45
@chuckj,用什么属性来获取渲染大小? – dumbledad 2015-07-05 15:39:39