2
votes

I am working with the ListView in Xamarin.Forms 1.4 and am wondering if there is a way to remove the header (and footer, for that matter...) from my ListView. As it is functioning "out of the box", I have extra white space at the top of my ListView, which if the Header property is set to a text value, would display that value; however, when left to the default, or even set to string.empty, the header still occupies space at the top.

Any guidance would be greatly appreciated!

*Edit 1: *

Just to clarify, I am not using XAML, but straight C#--here is the snippet I am using to create the ListView:

var listView = new ListView
{
    //Header = string.Empty,
    RowHeight = 160,
    ItemsSource = items,
    ItemTemplate = new DataTemplate(typeof(ItemCell))
};

I left the commented line in for context/reference...

*Edit 2: * Here is a screenshot from my iOS simulator demonstrating the issue--notice the top image as I scroll the ListView rolling under the header:

enter image description here

UPDATE: Solution

I marked @FredyWenger's answer as correct, but wanted to provide the actual fix that I implemented to take care of this issue. By removing/commenting out the lines below, I was able to get rid of the additional space at the tom and bottom of my ListView:

Content = new StackLayout
{
    //VerticalOptions = LayoutOptions.CenterAndExpand,
    //HorizontalOptions = LayoutOptions.Center,

    Children = { listView }
};
1
I don't see any default Header in my project, and my ListViews don't have a Header attribute. Have you tried removing the attribute altogether or setting it to null? If that doesn't work make a template with 0-height header, see developer.xamarin.com/guides/cross-platform/xamarin-forms/… - Sten Petrov
Sten, you probably aren't on version 1.4. Try update-package xamarin.forms in your NuGet console. - Rhyous
Sten, I just updated to 1.4. I don't see a default header size in 1.4 either. I can now add a header and get more space. But if I leave Header blank, it doesn't take space? Tom, can you post your Xaml? Is it on all platforms that you get extra space? - Rhyous
@Rhyous, I updated my question above...I am not using XAML, just C#. I included a snippet in my edit. - Tom Miller
@Rhyous, I am only targeting iOS at the moment. - Tom Miller

1 Answers

0
votes

I don't think that the "extra space" on top is coming from the ListView header (LV's don't should show a Header unless you explicitly define one). I think it's coming from another setting (mother-)control (e.g. a StackLayout). I would search there...