Skip to content

Commit 3d6b334

Browse files
committed
update samples
1 parent f9e2db6 commit 3d6b334

6 files changed

+25
-52
lines changed

components/Behaviors/samples/ItemsView Behaviors.md

Lines changed: 10 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -11,54 +11,21 @@ discussion-id: 532
1111
issue-id: 0
1212
icon: assets/icon.png
1313
---
14+
The new control `ItemsView` which can replace `ListView`&`GridView`, does not support `ISupportIncrementalLoading`.
1415

15-
<!-- To know about all the available Markdown syntax, Check out https://docs.microsoft.com/contribute/markdown-reference -->
16-
<!-- Ensure you remove all comments before submission, to ensure that there are no formatting issues when displaying this page. -->
17-
<!-- It is recommended to check how the Documentation will look in the sample app, before Merging a PR -->
18-
<!-- **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 -->
19-
<!-- Included images should be optimized for size and not include any Intellectual Property references. -->
16+
Here are some Behaviors to help you make `ItemsView` support `ISupportIncrementalLoading`.
2017

21-
<!-- 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. -->
18+
## NeedMoreItemTriggerBehaviorSample
2219

23-
# ItemsView Behaviors
24-
25-
TODO: Fill in information about this experiment and how to get started here...
26-
27-
## Custom Control
28-
29-
You can inherit from an existing component as well, like `Panel`, this example shows a control without a
30-
XAML Style that will be more light-weight to consume by an app developer:
31-
32-
>
33-
34-
## Templated Controls
35-
36-
The Toolkit is built with templated controls. This provides developers a flexible way to restyle components
37-
easily while still inheriting the general functionality a control provides. The examples below show
38-
how a component can use a default style and then get overridden by the end developer.
39-
40-
TODO: Two types of templated control building methods are shown. Delete these if you're building a custom component.
41-
Otherwise, pick one method for your component and delete the files related to the unchosen `_ClassicBinding` or `_xBind`
42-
classes (and the custom non-suffixed one as well). Then, rename your component to just be your component name.
43-
44-
The `_ClassicBinding` class shows the traditional method used to develop components with best practices.
45-
46-
### Implict style
20+
This trigger behavior can excute actions when the `ItemsView` scrolling to bottom.
21+
You can customize the loading behavior through actions, but note that you may need to debounce manually.
4722

4823
> [!SAMPLE NeedMoreItemTriggerBehaviorSample]
4924
50-
> [!SAMPLE LoadMoreItemBehaviorSample]
51-
52-
### Custom style
53-
54-
55-
## Templated Controls with x:Bind
56-
57-
This is an _experimental_ new way to define components which allows for the use of x:Bind within the style.
58-
59-
### Implict style
60-
61-
62-
### Custom style
25+
## LoadMoreItemBehaviorSample
6326

27+
If you don't have complex loading requirements, you can use this behavior.
28+
It automatically calls `ISupportIncrementalLoading.LoadMoreItemsAsync` when the `ItemsSource` changes, in addition to when `ItemsView` scrolls to the bottom.
29+
Besides, this behavior has a built-in debounce function.
6430

31+
> [!SAMPLE LoadMoreItemBehaviorSample]

components/Behaviors/samples/LoadMoreItemBehaviorSample.xaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@
2626
MinRowSpacing="5" />
2727
</ItemsView.Layout>
2828
<interactivity:Interaction.Behaviors>
29-
<controls:LoadMoreItemBehavior LoadingOffset="{x:Bind LoadingOffset, Mode=OneWay}" />
29+
<controls:LoadMoreItemBehavior
30+
IsActive="{x:Bind IsActive, Mode=OneWay}"
31+
LoadCount="{x:Bind (x:Int32)LoadCount, Mode=OneWay}"
32+
LoadingOffset="{x:Bind LoadingOffset, Mode=OneWay}" />
3033
</interactivity:Interaction.Behaviors>
3134
<ItemsView.ItemTemplate>
3235
<DataTemplate x:DataType="x:Int32">

components/Behaviors/samples/LoadMoreItemBehaviorSample.xaml.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99

1010
namespace BehaviorsExperiment.Samples;
1111

12-
[ToolkitSampleNumericOption("LoadingOffset", 100d, 50d, 500d, 50d, Title = "LoadingOffset")]
12+
[ToolkitSampleBoolOption(nameof(LoadMoreItemBehavior.IsActive), true, Title = nameof(LoadMoreItemBehavior.IsActive))]
13+
[ToolkitSampleNumericOption(nameof(LoadMoreItemBehavior.LoadingOffset), 100d, 50d, 500d, 50d, Title = nameof(LoadMoreItemBehavior.LoadingOffset))]
14+
[ToolkitSampleNumericOption(nameof(LoadMoreItemBehavior.LoadCount), 20, 1, 50, 1, Title = nameof(LoadMoreItemBehavior.LoadCount))]
1315

1416
[ToolkitSample(id: nameof(LoadMoreItemBehaviorSample), "LoadMoreItemBehavior", description: $"A sample for showing how to create and use a LoadMoreItemBehavior.")]
1517
public sealed partial class LoadMoreItemBehaviorSample : Page

components/Behaviors/samples/NeedMoreItemTriggerBehaviorSample.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
MinRowSpacing="5" />
2828
</ItemsView.Layout>
2929
<interactivity:Interaction.Behaviors>
30-
<controls:NeedMoreItemTriggerBehavior LoadingOffset="{x:Bind LoadingOffset, Mode=OneWay}">
30+
<controls:NeedMoreItemTriggerBehavior IsActive="{x:Bind IsActive, Mode=OneWay}" LoadingOffset="{x:Bind LoadingOffset, Mode=OneWay}">
3131
<core:CallMethodAction MethodName="IncrementCount" TargetObject="{x:Bind}" />
3232
</controls:NeedMoreItemTriggerBehavior>
3333

components/Behaviors/samples/NeedMoreItemTriggerBehaviorSample.xaml.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99

1010
namespace BehaviorsExperiment.Samples;
1111

12-
[ToolkitSampleNumericOption("LoadingOffset", 100d, 50d, 500d, 50d, Title = "LoadingOffset")]
12+
[ToolkitSampleBoolOption(nameof(NeedMoreItemTriggerBehavior.IsActive), true, Title = nameof(NeedMoreItemTriggerBehavior.IsActive))]
13+
[ToolkitSampleNumericOption(nameof(NeedMoreItemTriggerBehavior.LoadingOffset), 100d, 50d, 500d, 50d, Title = nameof(NeedMoreItemTriggerBehavior.LoadingOffset))]
1314

1415
[ToolkitSample(id: nameof(NeedMoreItemTriggerBehaviorSample), "NeedMoreItemTriggerBehavior", description: $"A sample for showing how to create and use a NeedMoreItemTriggerBehavior.")]
1516
public sealed partial class NeedMoreItemTriggerBehaviorSample : Page

components/Behaviors/src/LoadMoreItemBehavior.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ public int LoadCount
9696
/// </summary>
9797
public event Func<ItemsView, EventArgs, Task<bool>>? LoadMoreRequested;
9898

99-
private MUXC.ItemsRepeater? ItemsRepeater => (MUXC.ItemsRepeater?)this.ScrollView?.Content;
99+
private ItemsRepeater? ItemsRepeater => (ItemsRepeater?)this.ScrollView?.Content;
100100

101-
private ScrollView? ScrollView => this.AssociatedObject.ScrollView;
101+
private ScrollView? ScrollView => this.AssociatedObject?.ScrollView;
102102

103103
private long _scrollViewOnPropertyChangedToken;
104104
private long _itemsSourceOnPropertyChangedToken;
@@ -166,7 +166,7 @@ private async void ItemsSourceOnPropertyChanged(DependencyObject sender, Depende
166166
/// </summary>
167167
/// <remarks>
168168
/// <see cref="ItemsRepeater.SizeChanged"/> is the key to continuous loading.
169-
/// When new data is loaded, it makes the <see cref="Microsoft.UI.Xaml.Controls.ItemsRepeater"/> of the <see cref="FrameworkElement.ActualHeight"/> larger,
169+
/// When new data is loaded, it makes the <see cref="ItemsRepeater"/> of the <see cref="FrameworkElement.ActualHeight"/> larger,
170170
/// Or when the <see cref="ItemsView.ItemsSource"/> is changed to a different source or set for the first time, <see cref="FrameworkElement.ActualHeight"/> becomes 0.
171171
/// This method can reload the data.
172172
/// </remarks>
@@ -193,7 +193,7 @@ public async Task TryRaiseLoadMoreRequestedAsync()
193193
// Load until a new item is loaded in
194194
while (loadMore)
195195
{
196-
if (!this.IsActive || this.IsLoadingMore)
196+
if (this.AssociatedObject is null || !this.IsActive || this.IsLoadingMore)
197197
return;
198198

199199
// LoadMoreRequested is only triggered when the view is not filled.
@@ -231,7 +231,7 @@ public async Task TryRaiseLoadMoreRequestedAsync()
231231

232232
private int GetItemsCount()
233233
{
234-
return this.AssociatedObject.ItemsSource switch
234+
return this.AssociatedObject?.ItemsSource switch
235235
{
236236
ICollection list => list.Count,
237237
IEnumerable enumerable => enumerable.Cast<object>().Count(),

0 commit comments

Comments
 (0)