XAML 如何在WINUI 3中创建一个网格,该网格具有其容器的全部高度?

l2osamch  于 2023-11-14  发布在  其他
关注(0)|答案(1)|浏览(108)

我已经创建了一个网格,它没有采取其容器的全部高度。我不知道如何修复它。下面是代码...

<x:Class="WINUITMP.Views.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:controls="using:CommunityToolkit.WinUI.UI.Controls"
    xmlns:controls1="using:CommunityToolkit.WinUI.Controls"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:local="using:WINUITMP.Views"
    xmlns:local1="using:SegmentedExperiment.Samples"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:ui="using:CommunityToolkit.WinUI"
    mc:Ignorable="d">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="7*" />
            <RowDefinition Height="3*" />
        </Grid.RowDefinitions>
        <Frame x:Name="PageFrame" Grid.Row="0">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>

                <StackPanel Grid.Row="0" VerticalAlignment="Stretch">
                    <TextBlock Text="Hello" />
                </StackPanel>

                <StackPanel
                    Grid.Row="1"
                    VerticalAlignment="Stretch"
                    Background="AliceBlue">
                    <Grid VerticalAlignment="Stretch" Background="Yellow">
                        
                    </Grid>
                </StackPanel>
            </Grid>
        </Frame>
        <Grid Grid.Row="1" Padding="0,0,0,20">
            <Border
                Margin="0,20,0,0"
                BorderBrush="{StaticResource SurfaceStrokeColorDefaultBrush}"
                BorderThickness="1"
                CornerRadius="8" />
        </Grid>
    </Grid>
</Page>

字符串
我想让里面的网格占据整个容器的高度。

<StackPanel
    Grid.Row="1"
    VerticalAlignment="Stretch"
    Background="AliceBlue">
    <Grid VerticalAlignment="Stretch" Background="Yellow">
    </Grid>
</StackPanel>

rslzwgfq

rslzwgfq1#

StackPanel不会拉伸其子节点。
例如,对于下面的代码,LeftTextBox将具有其默认高度,而RightTextBox将具有拉伸高度。

<Grid ColumnDefinitions="*,*">
    <StackPanel Grid.Column="0">
        <TextBox x:Name="LeftTextBox" />
    </StackPanel>
    <Grid Grid.Column="1">
        <TextBox x:Nam="RightTextBox" />
    </Grid>
</Grid>

字符串
在本例中,StackPanel中的Grid将具有其默认高度,该高度为0,因为它是空的。
如果你想有一个拉伸的Grid,你需要用Grid而不是StackPanel Package 它。

相关问题