【问题标题】:How to make Scrollable Label in List Xamarin Forms如何在 Xamarin 表单列表中制作可滚动标签
【发布时间】:2020-03-27 06:05:50
【问题描述】:

我有一个固定行高的列表视图。在列表视图中有带有大描述的标签。我正在尝试使此标签能够滚动。谁能帮忙。

<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>

【问题讨论】:

  • 你不能有多个滚动,ListView 有自己的滚动添加一个滚动视图只是增加了问题!你的要求不能通过其他方式实现吗
  • Listview 已经滚动事件。请不要在Listview 中使用ScrollView,滚动手势会混淆目标位置。
  • 你能建议我任何其他方式吗?我了解列表视图和滚动视图不能一起使用。任何第三方插件或使我能够在每个单元格中显示大量文本的东西。我无法更改每个单元格的大小。它是固定的。

标签: xamarin xamarin.forms collectionviewsource


【解决方案1】:

正如 cmets 中所述,您不应该嵌套滚动视图,因为其行为不稳定。不过你可以使用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 的东西,但您可以将标签包装在ContentView 中,并将ContentViewHeightReqeust 设置为100。或者甚至可以将您的 Label Height Request 设置为 100 并看看会发生什么。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-26
    • 2023-03-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多