0

The GridView scrolls Horizontally and the screen can display up to 10 items. However when the page is loaded, the GridView is going insane and requesting to load 2475 items in LoadMoreItemAsync.

I limited the fetch function for each call to return 10 items each time. It just repeatedly calling LoadMoreItemAsync.

Now basically when I am not even scrolling the GridView it just loads itself.

Here is the GridView I used

<GridView ItemsSource="{Binding Data}" IncrementalLoadingThreshold="0">
    <GridView.ItemTemplate>
        <DataTemplate>
            <Image
                Margin="5"
                Stretch="UniformToFill"
                Source="{Binding Banner}"
            />
        </DataTemplate>
    </GridView.ItemTemplate>
    <GridView.ItemsPanel>
        <ItemsPanelTemplate>
            <ItemsWrapGrid MaximumRowsOrColumns="5" ItemWidth="192" ItemHeight="250" />
        </ItemsPanelTemplate>
    </GridView.ItemsPanel>
</GridView>

Here's the code behind

public IAsyncOperation<LoadMoreItemsResult> LoadMoreItemsAsync( uint count )
{
    Logger.Log( ID, string.Format( "Requesting to load {0} items", count ) );
    return Task.Run( async () =>
      {
          TaskCompletionSource<uint> ItemsLoaded = new TaskCompletionSource<uint>();

          ConnectedLoader.Connector = ( BookItem[] b ) =>
          {
              IEnumerable<T> Converted = Convert( b );
              uint i = 0;
              foreach ( T a in Converted )
              {
                  Add( a ); i++;
              }
              ItemsLoaded.SetResult( i );
          };

          ConnectedLoader.NextPage();

          return new LoadMoreItemsResult() { Count = await ItemsLoaded.Task };
      } ).AsAsyncOperation();
}

So how do I tell the GridView not to load so many items?

user1510539
  • 581
  • 1
  • 6
  • 17

1 Answers1

0

I figured it out. The issue seemed to be that I am placing the GridView inside a hub. Which is causing the GridView doesn't know where its limit since the hub section is expanding with it.

I found a similar question asked here: ISupportIncrementalLoading inside ScrollViewer not supported?

But currently the is no proper answer there. So I am keeping this here and hope someone will come with another solution.

Community
  • 1
  • 1
user1510539
  • 581
  • 1
  • 6
  • 17