WPF 一个布局的简单例子

1. 注意 Grid 里面,不管是行还是列,默认的尺寸大小就是,"1*"

2. 除了设置 “*”,固定值,还可以设置成 "Auto"

3. 结合图片的 Stretch 属性,可以做一些有意思的的效果

 

<Window x:Class="WpfApp24.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:WpfApp24"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"></RowDefinition>
            <RowDefinition Height="*"></RowDefinition>
        </Grid.RowDefinitions>

        <Grid Grid.Row="0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"></ColumnDefinition>
                <ColumnDefinition Width="Auto"></ColumnDefinition>
            </Grid.ColumnDefinitions>

            <Image Grid.Row="0" Source="Image1.jpg"></Image>
            <StackPanel Grid.Column="1" Background="AliceBlue" Width="300"></StackPanel>
        </Grid>
        <TextBlock Grid.Row="1"></TextBlock>
    </Grid>
</Window>

效果:

 

posted @ 2020-06-16 10:28  内心澎湃的水晶侠  阅读(255)  评论(0编辑  收藏  举报