为什么用StackLayout封装网格会限制网格的高度

时间:2018-08-01 00:47:40

标签: xamarin xamarin.forms

我在页面上和我放置此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似乎会限制其高度吗?

0 个答案:

没有答案