.Net MAUI 标签文本显示在屏幕外部,而不是多行文本

问题描述 投票:0回答:1

我正在移植一个 Xamarin 应用程序,其中包含 StackLayout 内的标签,不幸的是,文本不完整,并且看起来丢失的文本位于屏幕之外。

如何多行显示标签文本?

<StackLayout Orientation="Vertical" HorizontalOptions="Start">
    <Label Text="Pain and Stress Relief"
       FontSize="16"
       TextColor="Black"
       FontAttributes="Bold"
       VerticalOptions="Start" 
       HorizontalOptions="Start" />
    <Label Text="Users seeking relief from physical pain, inflammation, anxiety, or stress."
       FontSize="16"
       TextColor="Black"
       VerticalOptions="Start" 
       HorizontalOptions="Start" />
</StackLayout>

Xamarin 显示 enter image description here

.NET MAUI 显示 enter image description here

text label maui multiline
1个回答
0
投票

我找到的解决方案是使用 Grid 而不是使用 StackLayout

<Grid HorizontalOptions="FillAndExpand">
    <Grid.RowDefinitions>
        <RowDefinition Height="*" />
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <Label Grid.Row="0" Text="Pain and Stress Relief"
       x:Name="label_title_01"
       FontSize="16"
       TextColor="Black"
       FontAttributes="Bold"
       VerticalOptions="Start" 
       HorizontalOptions="Start" />
    <Label Grid.Row="1" Text="Users seeking relief from physical pain, inflammation, anxiety, or stress."
       x:Name="label01"
       FontSize="16"
       TextColor="Black"
       VerticalOptions="Start" 
       HorizontalOptions="Start" />
</Grid>
© www.soinside.com 2019 - 2024. All rights reserved.