如何在GRID XAML中做一个正方形列表?

hgc7kmma  于 2022-12-07  发布在  其他
关注(0)|答案(1)|浏览(139)

我尝试通过以下方式在XAML中创建网格:
GRID Type
我试过这样的东西,但我不知道如何添加红色方块。我必须在网格中做一个网格吗?
现在,我有一个代码

<Window x:Class="MonitorComenzi.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:MonitorComenzi"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="50"/>
            <RowDefinition />
        </Grid.RowDefinitions>
        
        <Grid.ColumnDefinitions>
            <ColumnDefinition/>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>
        
        <TextBlock Grid.Row="0" Grid.Column="0" FontSize="30" TextAlignment="Center" FontWeight="Bold" Foreground="Black">Comenzi plasate</TextBlock>
        <TextBlock Grid.Row="0" Grid.Column="1" FontSize="30" TextAlignment="Center" FontWeight="Bold" Foreground="Green">Comenzi preparate</TextBlock>
        
    </Grid>
    
</Window>
1tu0hz3e

1tu0hz3e1#

你可以创建嵌套的网格,这绝对是很好的,但是一个StackPanel也可以做到这一点。

<Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="50"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

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

        <TextBlock Grid.Row="0" Grid.Column="0" FontSize="30" TextAlignment="Center" FontWeight="Bold" Foreground="Black">Comenzi plasate</TextBlock>
        <TextBlock Grid.Row="0" Grid.Column="1" FontSize="30" TextAlignment="Center" FontWeight="Bold" Foreground="Green">Comenzi preparate</TextBlock>

        <StackPanel Orientation="Horizontal"
                    Margin="10"
                    Grid.Row="1"
                    Grid.Column="0">

            <Rectangle Fill="Red" Width="30" Height="30" Margin="5 0"/>
            <Rectangle Fill="Red" Width="30" Height="30" Margin="5 0"/>
            <Rectangle Fill="Red" Width="30" Height="30" Margin="5 0"/>
            <Rectangle Fill="Red" Width="30" Height="30" Margin="5 0"/>

        </StackPanel>
        
    </Grid>

相关问题