xamarin - 如何在 Xamarin 表单列表中制作可滚动标签
问题描述
我有一个固定行高的列表视图。在列表视图中有带有大描述的标签。我正在尝试使此标签能够滚动。任何人都可以帮忙吗?
<ListView ItemsSource="{Binding ServiceList, Mode=TwoWay}" RowHeight="100">
<ListView.ItemTemplate>
<DataTemplate x:DataType="models:ServiceModel">
<ViewCell>
<ScrollView
Margin="0"
Padding="0"
HeightRequest="50">
<Label
LineBreakMode="WordWrap"
Style="{StaticResource blackColorLabel}"
Text="{Binding ServiceDescription}" />
</ScrollView>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
解决方案
正如评论中提到的,你不应该嵌套滚动视图,因为行为是不稳定的。你可以使用BindableLayout
。
<StackLayout BindableLayout.ItemsSource="{Binding ServiceList}">
<BindableLayout.ItemTemplate>
<DataTemplate x:DataType="models:ServiceModel">
<ScrollView
Margin="0"
Padding="0"
HeightRequest="50">
<Label
LineBreakMode="WordWrap"
Style="{StaticResource blackColorLabel}"
Text="{Binding ServiceDescription}" />
</ScrollView>
</DataTemplate>
</BindableLayout.ItemTemplate>
RowHeight
不是一个东西BindableLayouts
,但你可以将你的 Label 包装在 a 中ContentView
并将 the设置HeightReqeust
为。或者甚至只是将您的设置为并查看它的作用。ContentView
100
Label Height Request
100
推荐阅读
- ethereum - Solidity - Truffle:错误:处理事务时出现 VM 异常:操作码无效,不是因为还原
- javascript - 如何将数组传递给函数,然后调用它 - javascript
- python - 如何正确获取具有 Retry-After 限制的 API
- jboss - 在 JBoss 中更新 MQ 资源适配器
- plotly.js - plotly.js,如何调整标题区域大小
- python - 如何在“AWS Step Functions”中共享数据而不在步骤之间传递数据
- php - 用于网络邮件的 HTML 净化器
- javascript - 如何从 onLoad 函数中导出数据?
- javascript - Mongoose 查询返回错误,但错误是我要查找的结果
- algorithm - 是什么让树遍历预先排序或有序?