diff --git a/Sample/VirtualListViewSample/MusicLibraryPage.xaml b/Sample/VirtualListViewSample/MusicLibraryPage.xaml
index 45ad698..508391c 100644
--- a/Sample/VirtualListViewSample/MusicLibraryPage.xaml
+++ b/Sample/VirtualListViewSample/MusicLibraryPage.xaml
@@ -72,6 +72,15 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/VirtualListView/Adapters/VirtualListViewAdapterBase.cs b/VirtualListView/Adapters/VirtualListViewAdapterBase.cs
index f3a1154..4c54722 100644
--- a/VirtualListView/Adapters/VirtualListViewAdapterBase.cs
+++ b/VirtualListView/Adapters/VirtualListViewAdapterBase.cs
@@ -2,7 +2,12 @@
public abstract class VirtualListViewAdapterBase : IVirtualListViewAdapter
{
- public virtual int GetNumberOfSections() => 1;
+ // This adapter assumes we only ever have 1 section
+ // however we really want to return 0 if there's no items at all
+ // So, ask the derived class how many items might be in the first
+ // section and if any, we return 1 section otherwise 0
+ public virtual int GetNumberOfSections() =>
+ GetNumberOfItemsInSection(0) > 0 ? 1 : 0;
public event EventHandler OnDataInvalidated;
diff --git a/VirtualListView/PositionalViewSelector.cs b/VirtualListView/PositionalViewSelector.cs
index 4cd3ee3..8b93b4a 100644
--- a/VirtualListView/PositionalViewSelector.cs
+++ b/VirtualListView/PositionalViewSelector.cs
@@ -28,12 +28,32 @@ int GetTotalCount()
{
var sum = 0;
- if (HasGlobalHeader)
- sum += 1;
+ var hasAtLeastOneItem = false;
+ var numberOfSections = Adapter.GetNumberOfSections();
+
+ if (HasGlobalHeader && numberOfSections > 0)
+ {
+ // Make sure that there's at least one section with at least
+ // one item, otherwise it's 'empty'
+ // The default adapter may always return 1 for number of sections
+ // so it's not enough to check that
+ for (int s = 0; s < numberOfSections; s++)
+ {
+ if (Adapter.GetNumberOfItemsInSection(s) > 0)
+ {
+ sum += 1;
+ // If we found one, we can stop looping
+ // since we just care to calculate a spot
+ // for the header cell if the adapter isn't empty
+ hasAtLeastOneItem = true;
+ break;
+ }
+ }
+ }
if (Adapter != null)
{
- for (int s = 0; s < Adapter.GetNumberOfSections(); s++)
+ for (int s = 0; s < numberOfSections; s++)
{
if (ViewSelector.SectionHasHeader(s))
sum += 1;
@@ -45,7 +65,9 @@ int GetTotalCount()
}
}
- if (HasGlobalFooter)
+ // Only count footer if there is already at least one item
+ // otherwise the adapter is empty and we shouldn't count it
+ if (HasGlobalFooter && hasAtLeastOneItem)
sum += 1;
return sum;