WPF下如何让控件大小跟着窗口的大小变化而变化

如题所述

<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=rectangle, Mode=OneWay}" />
</Grid>
</Window>
思路就是,用控件的高度宽度和窗体的相关属性做绑定。当然还可以用Converter做进一步的设置。
温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答