首页 > 解决方案 > 如何在 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>

标签: xamarinxamarin.formscollectionviewsource

解决方案


正如评论中提到的,你不应该嵌套滚动视图,因为行为是不稳定的。你可以使用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为。或者甚至只是将您的设置为并查看它的作用。ContentView100Label Height Request100


推荐阅读