Skip to content

Commit 900fcc2

Browse files
committed
Remove TSource default constructor requirement for IncrementalLoadingCollection
Addressing #616
1 parent c99b1d1 commit 900fcc2

File tree

4 files changed

+7
-24
lines changed

4 files changed

+7
-24
lines changed

Microsoft.Toolkit.Uwp.SampleApp/SamplePages/Incremental Loading Collection/IncrementalLoadingCollectionPage.xaml.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ protected override void OnNavigatedTo(NavigationEventArgs e)
4141
base.OnNavigatedTo(e);
4242

4343
// IncrementalLoadingCollection can be bound to a GridView or a ListView. In this case it is a ListView called PeopleListView.
44-
var collection = new IncrementalLoadingCollection<PeopleSource, Person>();
44+
var source = new PeopleSource();
45+
var collection = new IncrementalLoadingCollection<PeopleSource, Person>(source);
4546
PeopleListView.ItemsSource = collection;
4647

4748
// Binds the collection to the page DataContext in order to use its IsLoading and HasMoreItems properties.

Microsoft.Toolkit.Uwp.SampleApp/SamplePages/Microsoft Graph Service/MicrosoftGraphPage.xaml.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,9 @@ private async void GetMessagesButton_Click(object sender, RoutedEventArgs e)
117117
top = Convert.ToInt32(txtTop);
118118
}
119119

120+
var source = new MicrosoftGraphSource();
120121
var collection = new IncrementalLoadingCollection<MicrosoftGraphSource, Message>(
122+
source,
121123
top,
122124
async () =>
123125
{

Microsoft.Toolkit.Uwp/IncrementalLoadingCollection/IncrementalLoadingCollection.cs

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ namespace Microsoft.Toolkit.Uwp
3838
/// <seealso cref="ISupportIncrementalLoading"/>
3939
public class IncrementalLoadingCollection<TSource, IType> : ObservableCollection<IType>,
4040
ISupportIncrementalLoading
41-
where TSource : IIncrementalSource<IType>, new()
41+
where TSource : IIncrementalSource<IType>
4242
{
4343
/// <summary>
4444
/// Gets a value indicating the source of incremental loading.
@@ -117,27 +117,6 @@ private set
117117
}
118118
}
119119

120-
/// <summary>
121-
/// Initializes a new instance of the <see cref="IncrementalLoadingCollection{TSource, IType}"/> class optionally specifying how many items to load for each data page.
122-
/// </summary>
123-
/// <param name="itemsPerPage">
124-
/// The number of items to retrieve for each call. Default is 20.
125-
/// </param>
126-
/// <param name="onStartLoading">
127-
/// An <see cref="Action"/> that is called when a retrieval operation begins.
128-
/// </param>
129-
/// <param name="onEndLoading">
130-
/// An <see cref="Action"/> that is called when a retrieval operation ends.
131-
/// </param>
132-
/// <param name="onError">
133-
/// An <see cref="Action"/> that is called if an error occours during data retrieval.
134-
/// </param>
135-
/// <seealso cref="IIncrementalSource{TSource}"/>
136-
public IncrementalLoadingCollection(int itemsPerPage = 20, Action onStartLoading = null, Action onEndLoading = null, Action<Exception> onError = null)
137-
: this(new TSource(), itemsPerPage, onStartLoading, onEndLoading, onError)
138-
{
139-
}
140-
141120
/// <summary>
142121
/// Initializes a new instance of the <see cref="IncrementalLoadingCollection{TSource, IType}"/> class using the specified <see cref="IIncrementalSource{TSource}"/> implementation and, optionally, how many items to load for each data page.
143122
/// </summary>

docs/helpers/IncrementalLoadingCollection.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ The *GetPagedItemsAsync* method is invoked everytime the view need to show more
5454
`IncrementalLoadingCollection` can then be bound to a [ListView](https://msdn.microsoft.com/library/windows/apps/windows.ui.xaml.controls.listview.aspx) or a [GridView-like](https://msdn.microsoft.com/library/windows/apps/windows.ui.xaml.controls.gridview.aspx) control:
5555

5656
```csharp
57+
var source = new PeopleSource();
5758
var collection = new IncrementalLoadingCollection<PeopleSource, Person>();
5859
PeopleListView.ItemsSource = collection;
5960
```
@@ -62,7 +63,7 @@ The **IncrementalLoadingCollection** constructor accepts the following arguments
6263

6364
| Name | Description | Type |
6465
| --- | --- | --- |
65-
| source | An implementation of the **IIncrementalSource** interface that contains the logic to actually load data incrementally. If the source isn't provided to the constructor, it is created automatically. | IIncrementalSource |
66+
| source | An implementation of the **IIncrementalSource** interface that contains the logic to actually load data incrementally. | IIncrementalSource |
6667
| itemsPerPage | The number of items to retrieve for each call. Default is 20. | [Integer](https://msdn.microsoft.com/library/windows/apps/System.Int32) |
6768
| onStartLoading | (optional) An Action that is called when a retrieval operation begins. | [Action](https://msdn.microsoft.com/library/system.action.aspx) |
6869
| onEndLoading | (optional) An Action that is called when a retrieval operation ends. | [Action](https://msdn.microsoft.com/library/system.action.aspx) |

0 commit comments

Comments
 (0)