首页 > 技术文章 > WPF 主窗口缩放控件布局不变

chenxiaolinembed 2021-07-22 11:42 原文

参考MSDN 如下说明

Alignment、Margin 和 Padding 概述

Alignment、Margin 和 Padding 概述 - WPF .NET Framework | Microsoft Docs

XAML文件:

<Window x:Class="DeepDemo.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:DeepDemo"
        mc:Ignorable="d"
        Title="DeepDemo" Height="436" Width="857.8">
    <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
        <Button Content="Button" HorizontalAlignment="Left" Margin="10" Width="75" Height="30"/>
        <Button Content="Button" HorizontalAlignment="Right" Margin="10" Width="75" Height="30"/>
    </Grid>
</Window>

界面展示:

 

推荐阅读