为什么Listview隐藏文本的时间太长?

时间:2019-06-07 09:26:54

标签: xaml xamarin.forms

Listview隐藏长文本。

Visual Studio,Xamarin-Forms

ListView x:Name="listView" Refreshing="Refresh">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <StackLayout Margin="20,0,0,0" HorizontalOptions="FillAndExpand" Orientation="Horizontal">
<Label Text="Text and text"  FontAttributes="Bold" VerticalTextAlignment="Start" HorizontalOptions="StartAndExpand" />
<Label Text="Text text text text Text text text textText text text textText text text textText text text textText text text textText text text textText text text textText text text text " />
                        </StackLayout>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
</ListView>

我发现的唯一出路是RowHeight = 70 但是我不喜欢RowHeight = 70,因为到处文本的长度都是不同的

1 个答案:

答案 0 :(得分:1)

您需要将 HasUnevenRows 属性设置为 True ,并取消设置 RowHeight 属性。还要为标签设置 LineBreakMode

<ListView ItemsSource="{Binding List}" HasUnevenRows="True" SeparatorVisibility="None">
    <ListView.ItemTemplate>
        <DataTemplate>
            <ViewCell>
                <Grid>
                   <Label LineBreakMode="WordWrap"/>
                </Grid>
            </ViewCell>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>