我在页面上和我放置此XAML的内部都有一个StackLayout。我期望网格的高度为49,但实际上它更像是60。
<Grid Padding="20,10" HeightRequest="49" Margin="0" BackgroundColor="Green">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Label Grid.Column="0" Text="Phrase Display" VerticalTextAlignment="Center" Style="{StaticResource LabelText}" />
<local:SegmentedControl Grid.Column="1" ValueChanged="OnModeChanged" x:Name="segControlMode" HorizontalOptions="End" TintColor="Blue">
<local:SegmentedControl.Children>
<local:SegmentedControlOption Text="Learn" />
<local:SegmentedControlOption Text="Quiz" />
</local:SegmentedControl.Children>
</local:SegmentedControl>
</Grid>
所以我用另一个StackLayout包围了Grid,现在Grid的高度限制为49:
<StackLayout HeightRequest="49" Orientation="Vertical" Spacing="0" Margin="0" >
<Grid Padding="20,10" HeightRequest="49" Margin="0" BackgroundColor="Green">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Label Grid.Column="0" Text="Phrase Display" VerticalTextAlignment="Center" Style="{StaticResource LabelText}" />
<local:SegmentedControl Grid.Column="1" ValueChanged="OnModeChanged" x:Name="segControlMode" HorizontalOptions="End" TintColor="Blue">
<local:SegmentedControl.Children>
<local:SegmentedControlOption Text="Learn" />
<local:SegmentedControlOption Text="Quiz" />
</local:SegmentedControl.Children>
</local:SegmentedControl>
</Grid>
</StackLayout>
有人可以向我解释为什么用StackLayout封闭Grid似乎会限制其高度吗?