【发布时间】:2020-10-11 03:41:13
【问题描述】:
在我的 Xamarin Forms 应用程序中,我有一个简单的 ListView,绑定到一个集合。每个集合项由我在标签中显示的两个字符串组成。字符串可能不适合一行,在这种情况下,它们应该换行并占用多行。
我将代码缩减到最低限度,以便在此处发布:
<ScrollView Orientation="Vertical">
<ListView x:Name="lv" ItemsSource="{Binding MessageItems}" HasUnevenRows="True" Margin="10,10,30,10">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Frame VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" HasShadow="True" BorderColor="#0A2966" Margin="10,10,10,10">
<StackLayout Orientation="Vertical" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
<Label x:Name="ShortText" LineBreakMode="NoWrap" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
Short Text
</Label>
<Label x:Name="LongText" LineBreakMode="WordWrap" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Text="{Binding MessageText}">
This is a long message. It is so long it is going to wrap to the next line. It goes on and on and on to demonstrate word wrapping.
</Label>
</StackLayout>
</Frame>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ScrollView>
这一切都在 UWP 中按预期工作:
但在 WPF 中,它只是将每个标签显示在一行上,如果不适合则将文本截断:
我在 XAML 中指定了LineBreakMode="WordWrap",尽管它是默认值,但文本仍然不换行。
Xamarin 论坛中似乎有多个关于标签未包装的讨论,例如这个https://forums.xamarin.com/discussion/79278/word-wrap-on-label-doesnt-appear-to-be-working,但他们没有为我提供和回答。
Github 上有一个错误似乎准确地描述了我的问题 (https://github.com/xamarin/Xamarin.Forms/issues/3558),但它已被标记为已解决,并且该修复已在不久前合并。我认为它已经包含在最新版本的 Xamarin Forms 中,但我不确定如何检查。
我正在使用 Xamarin Forms 4.8.0.1534(最新版本),并且我还尝试了几种不同的 4.8.x 和 4.7.x 版本,但均未成功。
【问题讨论】:
-
Xamarin.Forms WPF 处于测试阶段。直到几周前我才知道它的存在。所有这些跨平台闪亮的新技术只有一个问题:它们有很多错误。
标签: xamarin.forms