Xamarin Forms 标签文本换行问题

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

我是新手,正在尝试使用 C# 中的 Xamarin 表单构建 Android 应用程序。在这里,我有一个被切断的标签。这是输出的屏幕截图: 输出截图

这里是页面的XAML代码。

<ContentPage.Content>
        <StackLayout Spacing="20" Padding="10">
            <StackLayout Orientation="Horizontal" VerticalOptions="FillAndExpand">
                <Label Text="Bridge Name:" FontSize="Medium"/>
                <Label Text="{Binding BridgeName}" FontSize="Medium"/>
            </StackLayout>
            
            <StackLayout Orientation="Horizontal">
                <Label Text="District:" FontSize="Medium" HorizontalOptions="Center" VerticalOptions="Center"/>
                <Label Text="{Binding District}" FontSize="Medium" HorizontalOptions="StartAndExpand" VerticalOptions="Center"/>
                <Label Text="Upazilla:" FontSize="Medium" HorizontalOptions="Center" VerticalOptions="Center" />
                <Label Text="{Binding Upazilla}" FontSize="Medium" HorizontalOptions="StartAndExpand" VerticalOptions="Center"/>
            </StackLayout>
        </StackLayout>
</ContentPage.Content>

我做错了什么?我该如何解决这个问题?我将不胜感激任何帮助。谢谢。

我发现,无论标签中有多少行,它都无法正确显示最后一行。如果总共有 2 行,那么第一行没问题,但第二行只显示垂直顶部。

c# android xamarin.forms uwp
1个回答
0
投票

您可以尝试将

Orientation="Vertical"
设置为
StackLayout

这里是供您参考的样本:

    <StackLayout Orientation="Vertical" Spacing="10" Padding="10">
            
            <StackLayout Orientation="Horizontal" BackgroundColor="Aqua">
                <Label Text="Bridge Name:" FontSize="Medium" />
                <Label Text="Construction of 81.0m Bridge at Lohagara Narail" FontSize="Medium" />
            </StackLayout>
            
            <StackLayout Orientation="Horizontal" BackgroundColor="Aqua">
                <Label Text="Bridge Name:" FontSize="Medium" />
                <Label Text="Construction of 81.0m Bridge at Lohagara Narail" FontSize="Medium" />
            </StackLayout>
            
            <StackLayout Orientation="Horizontal" BackgroundColor="Aqua">
                <Label Text="Bridge Name:" FontSize="Medium" />
                <Label Text="Construction of 81.0m Bridge at Lohagara Narail" FontSize="Medium" />
            </StackLayout>
    
            <StackLayout VerticalOptions="EndAndExpand" Orientation="Horizontal" BackgroundColor="Aqua">
                <Label Text="District:" FontSize="Medium" HorizontalOptions="Center" VerticalOptions="Center"/>
                <Label Text="Narail" FontSize="Medium" HorizontalOptions="StartAndExpand" VerticalOptions="Center"/>
                <Label Text="Upazilla:" FontSize="Medium" HorizontalOptions="Center" VerticalOptions="Center" />
                <Label Text="Lohagara" FontSize="Medium" HorizontalOptions="StartAndExpand" VerticalOptions="Center"/>
            </StackLayout>
            
    </StackLayout>

如果您想显示大量文本和数据,您可以使用 ListviewCollectionview

© www.soinside.com 2019 - 2024. All rights reserved.