我發現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