You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: The IncrementalLoadingCollection helpers greatly simplify the definition and usage of collections whose items can be loaded incrementally only when needed by the view
<!-- To know about all the available Markdown syntax, Check out https://docs.microsoft.com/contribute/markdown-reference -->
15
-
<!-- Ensure you remove all comments before submission, to ensure that there are no formatting issues when displaying this page. -->
16
-
<!-- It is recommended to check how the Documentation will look in the sample app, before Merging a PR -->
17
-
<!-- **Note:** All links to other docs.microsoft.com pages should be relative without locale, i.e. for the one above would be /contribute/markdown-reference -->
18
-
<!-- Included images should be optimized for size and not include any Intellectual Property references. -->
14
+
# Incremental Loading Collection Helpers
19
15
20
-
<!-- Be sure to update the discussion/issue numbers above with your Labs discussion/issue id numbers in order for UI links to them from the sample app to work. -->
16
+
The **IncrementalLoadingCollection** helpers greatly simplify the definition and usage of collections whose items can be loaded incrementally only when needed by the view, i.e., when user scrolls a [ListView](/uwp/api/Windows.UI.Xaml.Controls.ListView) or a [GridView](/uwp/api/Windows.UI.Xaml.Controls.GridView).
21
17
22
-
# IncrementalLoadingCollection
18
+
> [!Sample IncrementalLoadingCollectionSample]
23
19
24
-
TODO: Fill in information about this experiment and how to get started here...
20
+
[IIncrementalSource](/dotnet/api/microsoft.toolkit.collections.iincrementalsource-1) - An interface that represents a data source whose items can be loaded incrementally.
25
21
26
-
## Custom Control
22
+
[IncrementalLoadingCollection](/dotnet/api/microsoft.toolkit.uwp.incrementalloadingcollection-2) - An extension of [ObservableCollection](/dotnet/api/system.collections.objectmodel.observablecollection-1) such that its items are loaded only when needed.
27
23
28
-
You can inherit from an existing component as well, like `Panel`, this example shows a control without a
29
-
XAML Style that will be more light-weight to consume by an app developer:
| CurrentPageIndex | int | Gets or sets a value indicating The zero-based index of the current items page |
29
+
| HasMoreItems | bool | Gets a value indicating whether the collection contains more items to retrieve |
30
+
| IsLoading | bool | Gets a value indicating whether new items are being loaded |
31
+
| ItemsPerPage | int | Gets a value indicating how many items that must be retrieved for each incremental call |
32
+
| OnEndLoading |[Action](/dotnet/api/system.action)| Gets or sets an Action that is called when a retrieval operation ends |
33
+
| OnError | Action\<Exception> | Gets or sets an Action that is called if an error occours during data retrieval. The actual Exception is passed as an argument |
34
+
| OnStartLoading | Action | Gets or sets an Action that is called when a retrieval operation begins |
// Gets items from the collection according to pageIndex and pageSize parameters.
77
+
varresult= (frompinpeople
78
+
selectp).Skip(pageIndex*pageSize).Take(pageSize);
79
+
80
+
// Simulates a longer request...
81
+
awaitTask.Delay(1000);
82
+
83
+
returnresult;
84
+
}
85
+
}
86
+
```
87
+
88
+
The *GetPagedItemsAsync* method is invoked every time the view need to show more items.
89
+
90
+
`IncrementalLoadingCollection` can then be bound to a [ListView](/uwp/api/Windows.UI.Xaml.Controls.ListView) or a [GridView-like](/uwp/api/Windows.UI.Xaml.Controls.GridView) control:
<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE file in the project root for more information. -->
[ToolkitSample(id:nameof(IncrementalLoadingCollectionSample),"Incremental Loading Collection",description:$"A sample for showing how to create and use a IncrementalLoadingCollection.")]
// Licensed to the .NET Foundation under one or more agreements.
2
+
// The .NET Foundation licenses this file to you under the MIT license.
3
+
// See the LICENSE file in the project root for more information.
4
+
5
+
namespaceCommunityToolkit.WinUI;
6
+
7
+
/// <summary>
8
+
/// This interface represents a data source whose items can be loaded incrementally.
9
+
/// </summary>
10
+
/// <typeparam name="TSource">Type of collection element.</typeparam>
11
+
publicinterfaceIIncrementalSource<TSource>
12
+
{
13
+
/// <summary>
14
+
/// This method is invoked every time the view need to show more items. Retrieves items based on <paramref name="pageIndex"/> and <paramref name="pageSize"/> arguments.
15
+
/// </summary>
16
+
/// <param name="pageIndex">
17
+
/// The zero-based index of the page that corresponds to the items to retrieve.
18
+
/// </param>
19
+
/// <param name="pageSize">
20
+
/// The number of <typeparamref name="TSource"/> items to retrieve for the specified <paramref name="pageIndex"/>.
21
+
/// </param>
22
+
/// <param name="cancellationToken">
23
+
/// Used to propagate notification that operation should be canceled.
24
+
/// </param>
25
+
/// <returns>
26
+
/// Returns a collection of <typeparamref name="TSource"/>.
0 commit comments