WPF学习(6)- WPF布局Demo示例

xml 复制代码
<Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="auto" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="auto" />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <!--Top 整体停靠布局  -->
        <DockPanel Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Background="#126A74" Height="60">
            <TextBlock Text="XX应用程序" Foreground="White" FontSize="20" Margin="15,15" />
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
                <Border Height="35" Margin="10" BorderThickness="1" BorderBrush="#CA5100" Background="#CA5100"
                        CornerRadius="10">
                    <TextBlock Text="退出系统" Foreground="White" HorizontalAlignment="Center" VerticalAlignment="Center"
                               Margin="10 0 10 0" />
                </Border>
            </StackPanel>
        </DockPanel>
        <!--left-->
        <StackPanel Grid.Row="1" Grid.Column="0" Width="350" Orientation="Vertical">
            <Border Height="50" Margin="10" Padding="5" Background="#439D84">
                <TextBlock Text="参数区域" Margin="5" HorizontalAlignment="Center" VerticalAlignment="Center"
                           Foreground="White" FontSize="16" />
            </Border>
            <Border Height="50" Margin="10" Padding="5" Background="#9CDC7B">
                <TextBlock Text="参数区域" Margin="5" HorizontalAlignment="Center" VerticalAlignment="Center"
                           Foreground="White" FontSize="16" />
            </Border>
            <Border Height="110" Margin="10" Padding="5" Background="#E97752">
                <TextBlock Text="参数区域" Margin="5" HorizontalAlignment="Center" VerticalAlignment="Center"
                           Foreground="White" FontSize="16" />
            </Border>
        </StackPanel>
        <!--right-->
        <Grid Grid.Row="1" Grid.Column="1">
            <Border Margin="10" Padding="5" BorderThickness="1" BorderBrush="#F7BD93" CornerRadius="5"
                    Background="#FDD2B2">
                <TextBlock Text="主体区域" Margin="5" />
            </Border>
            <Border Width="150" Height="150" Margin="10" Padding="5" BorderThickness="1" Background="Red"
                    BorderBrush="Gray" CornerRadius="75">
                <TextBlock Text="开始运行" Margin="5" HorizontalAlignment="Center" FontSize="16" FontWeight="Bold"
                           VerticalAlignment="Center" Foreground="White" />
            </Border>
        </Grid>
        <!--bottom-->
        <Grid Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" Background="#CA5100">
            <TextBlock Text="版本:1.0  |  版权所有:百度有限公司  www.baidu.com" Margin="10 5 10 5" Foreground="White" />
        </Grid>
    </Grid>

我们通过Grid栅格布局出界面的主要区域,然后给每个区域进行二次布局,比如Top区域,我们DockPanel和StackPanel的组合,设计成左右两个子区域,左边是应用程序的名称,右边是退出按钮。

中间区域,分为两部分组成,左边是一个StackPanel,里面有一个Border,右边是一个Grid。(注:左侧的StackPanel改成Grid的效果会更好)。

底部区域是一个Grid和一个TextBlock内容控件。

相关推荐
Harm灬小海27 分钟前
【云计算学习之路】学习Centos7系统-Linux软件包管理
linux·运维·服务器·学习·云计算·yum·rpm
魔法阵维护师34 分钟前
从零开发游戏需要学习的c#模块,第十七章(显示真正的图片——精灵绘制)
学习·游戏
婷婷_17234 分钟前
JTAG (IEEE 1149.1)学习记录
学习·程序人生·debug·芯片·jtag·phy·eth/pcie
ygkl969841 分钟前
未完待续 模拟题
学习
几司1 小时前
OpenISP 模块拆解 · 第1讲:坏点校正 (DPC)
笔记·学习·isp
-To be number.wan1 小时前
计算机组成原理 | 定点数加减运算
学习·计算机组成原理
吃好睡好便好1 小时前
在Matlab中绘制杆状图
开发语言·学习·算法·matlab·信息可视化
Shadow(⊙o⊙)1 小时前
Shell进程替换,自定义Shell解释器——字符串库函数灵活操作!
linux·运维·服务器·开发语言·c++·学习
星幻元宇VR1 小时前
VR禁毒骑行系统|以沉浸式体验提升禁毒宣传教育效果
人工智能·科技·学习·安全·vr·虚拟现实
Hua-Jay1 小时前
OpenCV联合C++/Qt 学习笔记(二十三)----图像校正及单目位姿估计
c++·笔记·qt·opencv·学习·计算机视觉