控件的宽度、高度都跟随着Window的长度和宽度
<Window x:Name="window" x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<Rectangle x:Name="rectangle" Fill="#FF53A8F1" Width="{Binding ActualWidth, ElementName=window, Mode=OneWay}"
Height="{Binding ActualHeight, ElementName=window, Mode=OneWay}" />
</Grid>
</Window>
一个控件绑定另一个控件的大小
<Grid VerticalAlignment="Bottom" d:LayoutOverrides="Height">
<Border BorderBrush="Red" BorderThickness="1"
Width="{Binding Width, ElementName=textBlock, Mode=OneWay}"
Height="{Binding Height, ElementName=textBlock}"/>
<TextBlock x:Name="textBlock" Text="我是谁?我在哪?" Width="200" Height="30"/>
</Grid>