WPF の基本 - クラス 1 - レイアウトの概要

WPF の基本を始める

クラス1: レイアウト

1. グリッドの行と列の構造
*: 幅と高さを比例的に設定します。例: 0.6*

<Grid>
        <!--两行两列-->
        <Grid.RowDefinitions>
            <RowDefinition Height="*"></RowDefinition>
            <RowDefinition></RowDefinition>
        </Grid.RowDefinitions>

        <Grid.ColumnDefinitions>
            <ColumnDefinition></ColumnDefinition>
            <ColumnDefinition></ColumnDefinition>
        </Grid.ColumnDefinitions>
    </Grid>

2. <Grid.ColumnDefinitions> と同じディレクトリにある Grid.Column、Grid.ColumnSpan、Grid.Row、および Grid.RowSpan の行と列を選択します。

<Button Width="100" Height="50" Name="SB" Content="SB"></Button>
        <Border Grid.RowSpan="2" Grid.Column="0" Background="YellowGreen"></Border>
        <Border Grid.Row="0" Grid.Column="1" Background="AntiqueWhite"></Border>
        <!--<Border Grid.Row="1" Grid.Column="0" Background="Aqua"></Border>-->
        <Border Grid.Row="1" Grid.Column="1" Background="Aquamarine"></Border>

ここに画像の説明を挿入します
3. その他のコンテナ:
StackPanle:
Orientation=配置方向、余分な部分は自動的に折り返されず、非表示になります。

<StackPanel Orientation="Horizontal">
            <Button Width="100" Height="40" Click="Button_Click"></Button>
            <Button Width="100" Height="40"></Button>
            <Button Width="100" Height="40"></Button>
            <Button Width="100" Height="40"></Button>
            <Button Width="100" Height="40"></Button>
        </StackPanel>

ここに画像の説明を挿入します

WrapPanel
はデフォルトで横に配置されており、それを超えると自動的に配置されます。

<WrapPanel Grid.Row="1">
            <Button Width="100" Height="40"></Button>
            <Button Width="100" Height="40"></Button>
            <Button Width="100" Height="40"></Button>
            <Button Width="100" Height="40"></Button>
            <Button Width="100" Height="40"></Button>
            <Button Width="100" Height="40"></Button>
        </WrapPanel>

ここに画像の説明を挿入します

DockPanel は
側面を制御できます

<DockPanel Grid.Column="1" LastChildFill="False">
            <Button Width="100" Height="40" DockPanel.Dock="Right"></Button>
            <Button Width="100" Height="40" DockPanel.Dock="Bottom"></Button>
            <Button Width="100" Height="40" DockPanel.Dock="Top"></Button>
            <Button Width="100" Height="40" DockPanel.Dock="Left"></Button>
        </DockPanel>

ここに画像の説明を挿入します

おすすめ

転載: blog.csdn.net/qq_43622870/article/details/132426850