Skip to content

Commit e82c702

Browse files
michael-hawkerArlodotexe
authored andcommitted
Clean-up and remove code-behind for IncrementalLoadingCollection sample to use x:Bind instead
1 parent b1b24b6 commit e82c702

File tree

2 files changed

+10
-22
lines changed

2 files changed

+10
-22
lines changed

components/Collections/samples/IncrementalLoadingCollectionSample.xaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@
1919
<TextBlock Text="Items are loaded incrementally when the view needs to show them (i.e., when the user scrolls the ListView)"
2020
TextWrapping="Wrap" />
2121
<Button Margin="0,12,0,12"
22-
Click="RefreshCollection"
22+
Click="{x:Bind PeopleSource.RefreshAsync}"
2323
Content="Refresh collection"
2424
Style="{StaticResource AccentButtonStyle}" />
2525
<TextBlock>
2626
<Run Text="Is loading:" />
2727
<Run FontWeight="SemiBold"
28-
Text="{Binding IsLoading, Mode=OneWay}" />
28+
Text="{x:Bind PeopleSource.IsLoading, Mode=OneWay}" />
2929
</TextBlock>
3030
<TextBlock>
3131
<Run Text="Has more items:" />
3232
<Run FontWeight="SemiBold"
33-
Text="{Binding HasMoreItems, Mode=OneWay}" />
33+
Text="{x:Bind PeopleSource.HasMoreItems, Mode=OneWay}" />
3434
</TextBlock>
3535

3636
</StackPanel>
@@ -43,7 +43,8 @@
4343
BorderBrush="{ThemeResource CardStrokeColorDefaultBrush}"
4444
BorderThickness="1"
4545
CornerRadius="4">
46-
<ListView x:Name="PeopleListView">
46+
<ListView x:Name="PeopleListView"
47+
ItemsSource="{x:Bind PeopleSource, Mode=OneWay}">
4748
<ListView.ItemTemplate>
4849
<DataTemplate x:DataType="local:Person">
4950
<Grid>

components/Collections/samples/IncrementalLoadingCollectionSample.xaml.cs

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,20 @@ namespace CollectionsExperiment.Samples;
99
[ToolkitSample(id: nameof(IncrementalLoadingCollectionSample), "Incremental Loading Collection", description: $"A sample for showing how to create and use a IncrementalLoadingCollection.")]
1010
public sealed partial class IncrementalLoadingCollectionSample : Page
1111
{
12+
// IncrementalLoadingCollection can be bound to a GridView or a ListView. In this case it is a ListView called PeopleListView.
13+
public IncrementalLoadingCollection<PeopleSource, Person> PeopleSource { get; set; } = new(new PeopleSource());
14+
1215
public IncrementalLoadingCollectionSample()
1316
{
1417
this.InitializeComponent();
15-
Load();
16-
}
17-
private void Load()
18-
{
19-
// IncrementalLoadingCollection can be bound to a GridView or a ListView. In this case it is a ListView called PeopleListView.
20-
var collection = new IncrementalLoadingCollection<PeopleSource, Person>(new PeopleSource());
21-
PeopleListView.ItemsSource = collection;
22-
23-
// Binds the collection to the page DataContext in order to use its IsLoading and HasMoreItems properties.
24-
DataContext = collection;
25-
}
26-
27-
private async void RefreshCollection(object sender, RoutedEventArgs e)
28-
{
29-
var collection = (IncrementalLoadingCollection<PeopleSource, Person>)PeopleListView.ItemsSource;
30-
await collection.RefreshAsync();
3118
}
3219
}
3320

3421
/// <summary>
3522
/// A sample implementation of the <see cref="IIncrementalSource{TSource}"/> interface.
3623
/// </summary>
3724
/// <seealso cref="IIncrementalSource{TSource}"/>
38-
public class PeopleSource : IIncrementalSource<Person>
25+
public partial class PeopleSource : IIncrementalSource<Person>
3926
{
4027
private readonly List<Person> _people;
4128

@@ -94,7 +81,7 @@ public PeopleSource()
9481
/// <summary>
9582
/// A sample class used to show how to use the <see cref="IIncrementalSource{TSource}"/> interface.
9683
/// </summary>
97-
public class Person
84+
public partial class Person
9885
{
9986
/// <summary>
10087
/// Gets or sets the name of the person.

0 commit comments

Comments
 (0)