Xamarin Forms: Blank space is showing on top of Listviews in ios platform

Sreejith Sree 1,251 Reputation points
2022-03-15T09:11:56.05+00:00

On top of my all listviews in a project, there is a blank space on the ios platform, no such issue on android or windows.

Screenshot:

183155-screen-02-20220311-home.jpg

My code:

<ListView   
		x:Name="MyItems"  
		RefreshCommand="{Binding RefreshCommand}"  
		IsPullToRefreshEnabled="True"  
		IsRefreshing="{Binding IsRefreshing}"  
		HasUnevenRows="True">  
		<ListView.ItemTemplate>  
			<DataTemplate>  
				<ViewCell>  
					<ViewCell.View>  
						<StackLayout  
							Orientation="Vertical">   

							<StackLayout  
								HorizontalOptions="FillAndExpand"  
								VerticalOptions="FillAndExpand"  
								Orientation="Horizontal">  
								  
								</StackLayout>  
							</StackLayout>  
						</ViewCell.View>  
					</ViewCell>  
				</DataTemplate>  
			</ListView.ItemTemplate>  
		<ListView.Footer>  
			<Label/>  
		</ListView.Footer>  
	</ListView>  

Additional Details:

My XF version: 4.8.0.1821

My Project type is Portable

I need an urgent solution to this issue.

Developer technologies | .NET | Xamarin
0 comments No comments
{count} votes

Accepted answer
  1. JarvanZhang 23,971 Reputation points
    2022-03-16T03:11:27.037+00:00

    Hello,​ SreejithSree-2948

    This isse occurs on iOS 15. What is version of Xamarin.Forms in your project? Please update the package to 5.0.0.2244 or higher and test again. The issue will be fixed.

    Or you can create a custom renderer to specify a value to the SectionHeaderTopPadding property.

       protected override void OnElementChanged(ElementChangedEventArgs<ListView> e)  
       {  
           base.OnElementChanged(e);  
           if (Control != null)  
           {  
               if (UIDevice.CurrentDevice.CheckSystemVersion(15, 0))  
                   Control.SectionHeaderTopPadding = new nfloat(0);  
           }  
       }  
    

    Similar issue thread, you could refer to: https://github.com/xamarin/Xamarin.Forms/issues/14664#issuecomment-985101722

    Best Regards,

    Jarvan Zhang


    If the response is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Sreejith Sree 1,251 Reputation points
    2022-03-15T15:05:47.977+00:00

    Solved by adding below custom render on ios project:

    [assembly: ExportRenderer(typeof(ListView), typeof(LVRenderer))]
    namespace YourNameSpace.iOS
    {
        public class LVRenderer : ListViewRenderer
        {
            public LVRenderer()
            {
            }
    
            protected override void OnElementChanged(ElementChangedEventArgs<ListView> e)
            {
                base.OnElementChanged(e);
                if (Control != null)
                {
                    Control.SectionHeaderTopPadding = new nfloat(0);
                }
            }
        }
    }
    
    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.