You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Xamarin Forms标签文本与元素显示异常问题求助

Xamarin Forms Label文本显示不全及布局异常问题

在Xamarin Forms中遇到Label无法显示全部文本、屏幕外元素无法展示的问题。旋转手机可临时解决,但数据重新加载或更新后问题复现。该问题在模拟器、真机均会出现,且存在于多个不同项目中。

加载时显示情况:Label仅显示部分文本,超出屏幕的内容被截断,无法滚动查看
切换方向时显示情况:文本全部正常显示,可完整查看内容
恢复方向时显示情况:文本再次被截断,回到加载时的异常状态

已尝试以下解决方案但未解决:

  • 修改字体大小:
    TableLabel.FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label));
  • 设置换行模式:
    TableLabel.LineBreakMode = LineBreakMode.WordWrap;
  • 配置布局选项:
    TableLabel.HorizontalOptions = LayoutOptions.FillAndExpand;
    TableLabel.VerticalOptions = LayoutOptions.FillAndExpand;

XAML代码

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="Raspisanie.MainPage">
    <ScrollView>
        <StackLayout>
            <StackLayout>
                <Button Text="ChangingSides" Clicked="ChangingSidesClicked"/>
                <StackLayout Orientation="Horizontal" HorizontalOptions="Start">
                    <Button Text="Previous table" Clicked="OnPreviousClicked"/>
                    <Button Text="Next table" Clicked="OnNextClicked"/>
                </StackLayout>
            </StackLayout>
            <Label x:Name="TableLabel" Text="The table will be displayed here"/>
        </StackLayout>
    </ScrollView>
</ContentPage>

CS代码(注:此代码不影响显示,元素创建时已出现问题)

string responseData = await response.Content.ReadAsStringAsync();
TableLabel.Text = responseData;

内容的提问来源于stack exchange,提问作者N44

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.18 13:45:57