Realize list item properties when the container changes for UI

This commit is contained in:
Ross Luengen
2025-09-23 10:04:13 -07:00
parent f995e414b7
commit a690ea96a5
3 changed files with 10 additions and 7 deletions

View File

@@ -200,13 +200,6 @@ public partial class ListViewModel : PageViewModel, IDisposable
// Check for cancellation before initializing first twenty items
cancellationToken.ThrowIfCancellationRequested();
var firstTwenty = newViewModels.Take(20);
foreach (var item in firstTwenty)
{
cancellationToken.ThrowIfCancellationRequested();
item?.SafeInitializeProperties();
}
// Cancel any ongoing search
_cancellationTokenSource?.Cancel();

View File

@@ -276,6 +276,7 @@
IsDoubleTapEnabled="True"
IsItemClickEnabled="True"
ItemClick="Items_ItemClick"
ContainerContentChanging="ItemsList_ContainerContentChanging"
ItemTemplate="{StaticResource ListItemViewModelTemplate}"
ItemsSource="{x:Bind ViewModel.FilteredItems, Mode=OneWay}"
RightTapped="Items_RightTapped"
@@ -295,6 +296,7 @@
IsDoubleTapEnabled="True"
IsItemClickEnabled="True"
ItemClick="Items_ItemClick"
ContainerContentChanging="ItemsList_ContainerContentChanging"
ItemTemplateSelector="{StaticResource GridItemTemplateSelector}"
ItemsSource="{x:Bind ViewModel.FilteredItems, Mode=OneWay}"
RightTapped="Items_RightTapped"

View File

@@ -427,4 +427,12 @@ public sealed partial class ListPage : Page,
Keyboard,
Pointer,
}
private void ItemsList_ContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args)
{
if (args.Item is ListItemViewModel item)
{
item.SafeInitializeProperties();
}
}
}