下面我来举个例子说明如何用Grid或DockPanel来实现自适应窗体。
让我们新建一个WPF工程,完成后我们打开对应的XAML文件,可以看到VS已经自动添加了<Grid></Grid>这一对标签,下面我就以Grid为例展示如何实现窗体自适应(如果需要使用DockPanel只需把<Grid></Grid>换成<DockPanel></DockPanel>即可)。
<Window x:Class="Auto_Match_Window.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>
</Grid>
</Window>
下面往Grid里面添加2个控件TextBlock和Button,如下:
<Window x:Class="Auto_Match_Window.MainWi