Xaml 制作响应性框架Xamarin表单

Xaml 制作响应性框架Xamarin表单,xaml,xamarin.forms,Xaml,Xamarin.forms,我试着用沙马林的方式压制他,但没有运气。他是我的尝试 <StackLayout Spacing="0" Padding="20"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="10"/> <RowDefinition Height="40"/> </Grid.RowDefinition

我试着用沙马林的方式压制他,但没有运气。他是我的尝试

<StackLayout Spacing="0" Padding="20">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="10"/>
            <RowDefinition Height="40"/>
        </Grid.RowDefinitions>

        <Label x:Name="pol1" Text="some text" FontSize="Title" Grid.Row="1"/>
        <Frame BackgroundColor="Gray" Grid.Row="2" HasShadow="True" CornerRadius="10">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="20"/>
                    <RowDefinition Height="20"/>
                    <RowDefinition Height="200"/>
                    <RowDefinition Height="20"/>
                    <RowDefinition Height="5"/>
                    <RowDefinition Height="5"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
                <StackLayout Spacing="0">
                    <Label Text="some text" Grid.Row="2"/>
                    <Label Text="some text" Grid.Row="3"/>
                    <Label Text="some text" Grid.Row="4"/>
                    <Label Text="some text some textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome text" Grid.Row="5"/>
                    <Label Text="some textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome text" Grid.Row="6"/>
                    <Label Text="some textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome text" Grid.Row="6"/>
                </StackLayout>
            </Grid>
        </Frame>
    </Grid>
</StackLayout> 


但是框架不能缩放到文本。我想让它缩放到文本的末尾。

这里的StackLayout用法和索引是个问题。在这种情况下,父布局将无法正确测量大小。我已经删除了不需要的堆栈布局,使其优化。现在我可以用下面的代码得到想要的结果

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="10"/>
        <RowDefinition Height="40"/>
    </Grid.RowDefinitions>

    <Label x:Name="pol1" Text="some text" FontSize="Title" Grid.Row="1"/>
    <Frame BackgroundColor="Gray" Grid.Row="2" HasShadow="True" CornerRadius="10">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="20"/>
                <RowDefinition Height="20"/>
                <RowDefinition Height="200"/>
                <RowDefinition Height="20"/>
                <RowDefinition Height="5"/>
                <RowDefinition Height="5"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
            <StackLayout Spacing="0">
                <Label Text="some text" Grid.Row="2"/>
                <Label Text="some text" Grid.Row="3"/>
                <Label Text="some text" Grid.Row="4"/>
                <Label Text="some text some textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome text" Grid.Row="5"/>
                <Label Text="some textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome text" Grid.Row="6"/>
                <Label Text="some textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome text" Grid.Row="6"/>
            </StackLayout>
        </Grid>
    </Frame>
</Grid>

我得到了下面的输出。我希望它能帮助你


如果要将标签指定给网格单元,则StackLayout不可用needed@Jason是的,谢谢。你可以在答案中写下你的解决方案,或者标出正确的答案,这将帮助更多有同样问题的人:)。