Xamarin Formns:在列表视图中的数据之后创建多个空行

时间:2018-11-14 16:42:25

标签: xamarin.forms

PFB我的列表视图的代码,

 <ListView HasUnevenRows="true" ItemsSource="{Binding UserEmailList}" IsGroupingEnabled="true">
            <ListView.GroupHeaderTemplate>
                <DataTemplate>
                    <ViewCell>
                        <ViewCell.View>
                            <StackLayout Orientation="Vertical" Spacing="0" Margin="0" Padding="0">
                                <BoxView Style="{StaticResource separator}"></BoxView>
                                <Label Text="{Binding Heading}" Style="{StaticResource labelHeaderTitle}" />
                                <BoxView Style="{StaticResource separator}"></BoxView>
                            </StackLayout>
                        </ViewCell.View>
                    </ViewCell>
                </DataTemplate>
            </ListView.GroupHeaderTemplate>
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <ViewCell.View>
                            <StackLayout Orientation="Horizontal" Spacing="0" >
                              <StackLayout IsVisible="{Binding UserEmailDetails.HasEmailAddress}" Orientation="Horizontal" HorizontalOptions="FillAndExpand">
                                <Label Text="{Binding UserEmailDetails.EmailAddress}" Style="{StaticResource labelListItem}" HorizontalOptions="FillAndExpand">
                                  <Label.GestureRecognizers>
                                    <TapGestureRecognizer Tapped="SelectEmailAddress_Tapped" CommandParameter="{Binding UserEmailDetails}" />
                                  </Label.GestureRecognizers>
                                </Label>
                                <Image HeightRequest="16" HorizontalOptions="End" VerticalOptions="Center" Source="arrow.png" Margin="0,0,15,0">
                                </Image>
                              </StackLayout>
                              <StackLayout IsVisible="{Binding UserEmailDetails.HasEmailAddress, Converter={StaticResource NotConverter}}" Padding="15,0,0,0">
                                <Label Text="Add email" Style="{StaticResource labelLink}">
                                  <Label.GestureRecognizers>
                                    <TapGestureRecognizer Tapped="SelectEmailAddress_Tapped" CommandParameter="{Binding UserEmailDetails}" />
                                  </Label.GestureRecognizers>
                                </Label>
                              </StackLayout>
                            </StackLayout>
                        </ViewCell.View>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>

即使只有两行,在IOS上也会填充多个空行,如下面的快照所示。

请让我知道如何避免这种情况,并让事情在Android和IOS上都能正常工作

enter image description here

1 个答案:

答案 0 :(得分:2)

我可以通过在ListView属性上设置SeparatorVisibility =“ None”来隐藏Separator。如果您仍然需要分隔符,我将在ViewCell中定义。

<ListView HasUnevenRows="true" SeparatorVisibility="None">

另一种方法是将“空页脚”放在列表视图中:

<ListView>
    <ListView.Footer>
        <Label />
    </ListView.Footer>
</ListView>

我希望其中之一能对您有所帮助。让我知道是否有事。