在Xamarin ListView中呈现ListViewItem时出现问题

时间:2019-06-23 04:16:31

标签: xaml xamarin xamarin.forms

大多数情况下,在Xamarin中使用ListView效果很好,但是对于某些项目,我遇到了渲染问题,StackLayout中的项目重叠(堆叠在Z轴而不是Y轴上!),我想知道可能导致的原因:

Issue

当细胞回收到最初的高度时,似乎会发生这种情况。

xaml非常简单,它是ListView(分组的)和itemtemplate的绑定:

<ListView.ItemTemplate>
    <DataTemplate>
        <ViewCell>
            <StackLayout Padding="10,5" BackgroundColor="{Binding BackgroundColor}">
                <!-- The following IsVisible property is probably what cause 
                     the change of height of cells, and when recycled, 
                     the cells do not resize well -->
                <Label Text="{Binding Date}" TextColor="Black" LineBreakMode="NoWrap" 
                       IsVisible="{Binding Date,Converter={StaticResource INNTBC}}" Style="{DynamicResource ListItemTextStyle}" FontSize="12" />
                <StackLayout Orientation="Horizontal">
                    <Label Text="{Binding Participant.FirstName}" TextColor="Black" LineBreakMode="NoWrap" Style="{DynamicResource ListItemTextStyle}" FontSize="16" />
                    <Label Text="{Binding Participant.LastName}" TextColor="Black" ineBreakMode="NoWrap" Margin="5,0,0,0" Style="{DynamicResource ListItemTextStyle}" FontSize="16" />
                    <Label Text="{Binding Participant.BirthDate}" TextColor="Black" LineBreakMode="NoWrap" Margin="5,0,0,0" Style="{DynamicResource ListItemTextStyle}" FontSize="12" />
                </StackLayout>
                <StackLayout HeightRequest="1" BackgroundColor="LightGray" Margin="20,1,20,1" HorizontalOptions="CenterAndExpand"></StackLayout>
            </StackLayout>
        </ViewCell>
    </DataTemplate>
</ListView.ItemTemplate>

有任何线索吗?

1 个答案:

答案 0 :(得分:0)

问题来自应用于clear(i : number){ //this function removes input field console.log("delete item index:"+i); arrayItems[i]["isdelete"] = true; (this.personalForm.get('other') as FormArray).removeAt(i); // Try this if you want to update form value as well ((this.personalForm.get('other') as FormArray).at(i) as FormGroup).get("isdelete").setValue(true); } 的{​​{1}}。回收后的高度无法正确计算。

这不是最佳选择,但最后我通过将CachingStrategy="RecycleElement"设置为ListView来解决了这个问题。