想要删除 Space 前后 ListView GroupHeader Xamarin Forms-iOS

Want to remove Space Before and after ListView GroupHeader Xamarin Forms-iOS

listview 中的每个 GroupHeader 前后都有 space。我想删除所有这些 space。这种情况只发生在 iOS 个模拟器和设备上。 只是为了进一步了解它以前工作正常但现在 Listview groupheader 在每一行之后带有 space。

下图 - 这是我想要实现的,之前它也可以正常工作 This is what i want to achieve and previously it was working also as accepted

这是在每个 GroupHeader 之后发生的情况,space 仅在 ios 中出现。 This what is happening now after a every GroupHeader there is space coming only in ios

                    <Grid Padding="0,0,0,0">
                    <ListView
                        x:Name="listView"
                        Margin="0,20,0,0"
                        ios:ListView.GroupHeaderStyle="Grouped"
                        GroupDisplayBinding="{Binding GroupDetailName}"
                        IsGroupingEnabled="true"
                        SeparatorVisibility="None">
                        <ListView.ItemTemplate>
                            <DataTemplate>
                                <ViewCell>
                                    <StackLayout Orientation="Vertical" VerticalOptions="Center">
                                        <StackLayout.GestureRecognizers>
                                            <TapGestureRecognizer
                                                CommandParameter="{Binding .}"
                                                NumberOfTapsRequired="1"
                                                Tapped="TapGestureRecognizer_Tapped" />
                                        </StackLayout.GestureRecognizers>
                                        <StackLayout Orientation="Horizontal">
                                            <Label
                                                Margin="50,10,0,10"
                                                FontSize="16"
                                                Text="{Binding GroupAppName}"
                                                VerticalOptions="Center"
                                                VerticalTextAlignment="Center" />
                                        </StackLayout>
                                    </StackLayout>
                                </ViewCell>
                            </DataTemplate>
                        </ListView.ItemTemplate>
                        <ListView.GroupHeaderTemplate>
                            <DataTemplate>
                                <ViewCell>
                                    <StackLayout BackgroundColor="Red" Orientation="Horizontal">
                                        <StackLayout.GestureRecognizers>
                                            <TapGestureRecognizer
                                                CommandParameter="{Binding .}"
                                                NumberOfTapsRequired="1"
                                                Tapped="Groupnameclicked" />
                                        </StackLayout.GestureRecognizers>
                                        <ImageButton
                                            Margin="20,12,8,6"
                                            BackgroundColor="Red"
                                            CommandParameter="{Binding .}"
                                            HeightRequest="14"
                                            Source="{Binding StateIcon}"
                                            WidthRequest="15">
                                            <!--<Image.Triggers>
                                                    <DataTrigger
                                                        Binding="{Binding Isvisible}"
                                                        TargetType="Image"
                                                        Value="True">
                                                        <Setter Property="Source" Value="arrowdownnew.png" />
                                                    </DataTrigger>
                                                </Image.Triggers>-->
                                        </ImageButton>
                                        <Label
                                            Margin="0,0,0,0"
                                            FontSize="18"
                                            HorizontalOptions="Start"
                                            Text="{Binding GroupName}"
                                            TextColor="White"
                                            VerticalOptions="Center"
                                            VerticalTextAlignment="Center" />
                                    </StackLayout>

                                </ViewCell>
                            </DataTemplate>
                        </ListView.GroupHeaderTemplate>
                    </ListView>
                </Grid>

您可以使用自定义渲染器删除 space。

请参考以下代码:

[assembly:ExportRenderer(typeof(ListView),typeof(MyRenderer))]
namespace Formssss.iOS
{
public class MyRenderer : ListViewRenderer
{
    public MyRenderer()
    {
    }
    protected override void OnElementChanged(ElementChangedEventArgs<ListView> e)
    {
        base.OnElementChanged(e);
        if(Control != null)
        {
            Control.SectionHeaderTopPadding = new nfloat(0);
        }
    }
}
}

以下是 custom-renderer 的官方文档: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/custom-renderer/