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内容控件。

相关推荐
marshalVS31 分钟前
前端学习-节点操作(三十五)
学习
优雅永不过时·2 小时前
Three.js编辑器百度搜索 Top 1
前端·javascript·学习·编辑器·three
凉夜十三4 小时前
32单片机学习记录2之按键
单片机·学习
麻花20134 小时前
WPF正则表达式验证输入是否包含中文字母数字,不能是纯符号
wpf
無铭之辈4 小时前
学习Vue的必要基础
前端·vue.js·学习
虾球xz5 小时前
游戏引擎学习第99天
javascript·学习·游戏引擎
练小杰6 小时前
【MySQL例题】我在广州学Mysql 系列——有关数据备份与还原的示例
android·数据库·经验分享·sql·学习·mysql
larry_dongy6 小时前
VMware Workstate 的 Ubuntu18 安装 vmware tools(不安装没法共享)
学习·ubuntu
菜鸟码农016 小时前
Datawhale 组队学习 wow-agent task1 学习总结
python·学习·datawhale
靡不有初1117 小时前
CCF-CSP第34次认证第二题——矩阵重塑(其二)【需反复思考学习!!!】
c++·学习·线性代数·矩阵·备考·ccfcsp