我已经创建了一个网格,它没有采取其容器的全部高度。我不知道如何修复它。下面是代码...
<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>
型
1条答案
按热度按时间rslzwgfq1#
StackPanel
不会拉伸其子节点。例如,对于下面的代码,LeftTextBox将具有其默认高度,而RightTextBox将具有拉伸高度。
字符串
在本例中,
StackPanel
中的Grid
将具有其默认高度,该高度为0,因为它是空的。如果你想有一个拉伸的
Grid
,你需要用Grid
而不是StackPanel
Package 它。