Replies: 5 comments 1 reply
-
I did not pagination but maybe this helps you although. Done listview inside of FeedView (thought that is a have to for IFeedList which I did use via mvux
MainModel.cs property:
GalleryImageService.cs
Item DataTemplate in page.resources:
I think on your code is maybe missing the data type in the DataTemplate header? |
Beta Was this translation helpful? Give feedback.
-
Thanks for this. Much appreciated. Yes, I did something similar with a FeedView and got the list to populate (first page only, because it does not support pagination). I also bound it to a Observable Collection and it fully populated. So I think the [Data type] in the DataTemplate might not be the issue. I tried adding it however, but still no improvement. Appreciate your help though. |
Beta Was this translation helpful? Give feedback.
-
Hi @hbraasch thanks for the sample attached. I validated your code, and some things are not correctly set; sorry if this was clear from the documentation: First, you have a mix of MVVM and MVUX. It's okay to have both, although I suggest you stick to one. 1: For example, your IListFeed is inside a MainViewModel class object. The correct setup would require all this logic inside a using System.Diagnostics;
namespace UnoPaginateTester.Presentation;
public record DisplayItem(string Description);
public partial record MainModel
{
private INavigator _navigator;
public string? Title { get; }
public IState<string> Name => State<string>.Value(this, () => string.Empty);
public IListFeed<DisplayItem> DataAuto =>
ListFeed.AsyncPaginated<DisplayItem>(async (PageRequest pageRequest, CancellationToken ct) =>
await GetDataAsync(pageSize: pageRequest.DesiredSize ?? 5, firstItemIndex: pageRequest.CurrentCount, ct));
public MainModel(
IStringLocalizer localizer,
IOptions<AppConfig> appInfo,
INavigator navigator)
{
_navigator = navigator;
Title = "Main";
Title += $" - {localizer["ApplicationName"]}";
Title += $" - {appInfo?.Value?.Environment}";
}
public async Task GoToSecondView()
{
var pageRequest = new PageRequest { DesiredSize = 5, CurrentCount = 0 };
var data = await GetDataAsync(pageRequest.DesiredSize ?? 5, pageRequest.CurrentCount, CancellationToken.None);
Debug.WriteLine($"Fetched {data.Count} items.");
var name = await Name;
await _navigator.NavigateViewModelAsync<SecondViewModel>(this, data: new Entity(name!));
}
public async ValueTask<IImmutableList<DisplayItem>> GetDataAsync(uint pageSize, uint firstItemIndex, CancellationToken ct)
{
// convert to int for use with LINQ
var (size, count) = ((int)pageSize, (int)firstItemIndex);
// fake delay to simulate loading data
await Task.Delay(TimeSpan.FromSeconds(1), ct);
// this is where we would asynchronously load actual data from a remote data store
var people = GenerateData();
Debug.WriteLine($"Fetching Data: Count: {count} items.");
return people
.Skip(count)
.Take(size)
.ToImmutableList();
}
private List<DisplayItem> GenerateData()
{
var items = new List<DisplayItem>();
for (var i = 0; i < 100; i++)
{
items.Add(new DisplayItem($"Item{i}"));
}
return items;
}
} Note: You must rename the MainViewModel class, comment it out, or just delete it. 2: You are already using Here, I added MVUX to the list of features that were previously set. <UnoFeatures>
Material;
Hosting;
Toolkit;
Logging;
Mvvm;
Configuration;
Http;
Serialization;
Localization;
Navigation;
MVUX;
</UnoFeatures> You will also need to remove the references to Delete these lines of code <ItemGroup>
<PackageReference Include="Uno.Extensions.Reactive" />
</ItemGroup> and these: <ItemGroup>
<PackageVersion Include="Uno.Extensions.Reactive" Version="5.1.3" />
</ItemGroup> 3: This is just a note: this project was created using an old version of the
Important: You can force MVUX to use the latest naming convention ( [assembly: Uno.Extensions.Reactive.Config.BindableGenerationTool(3)] With the abovementioned changes, you should get your pagination app to work. More about Pagination and MVUX Note: I have my changes locally. If you'd like me to push them, just let me know. uno_mvux_pagination.mp4 |
Beta Was this translation helpful? Give feedback.
-
@ajpinedam Do you think I can get it to work with MVVM? |
Beta Was this translation helpful? Give feedback.
-
Finally, got something to work, but with a completely different approach. Using the code from: https://nicksnettravels.builttoroam.com/incremental-loading-pagination-with-mvvm-and-mvux/ This makes use of an enhanced ObservableCollection. Personally, I do not think the Uno Listview work with IListFeed, unless used under MVUX. I wish someone can confirm that and update the documentation. It might stop one from wasting hours trying to get it to work. |
Beta Was this translation helpful? Give feedback.
-
I'm trying to work with ListView pagination and have set up a sample based on the Uno documentation.
It is based on the sample template with just a ListView added to the MainPage, with paging code in the viewModel
The ListView is defined in the XAML:
The pagination code in the ViewModel is the following:
If I set the listview datasource to
ItemsSource="{Binding DataItems}"
, it displays fineIf I set the listview datasource to
ItemsSource="{Binding DataAuto}"
, the DataAuto method is reached, but the ListFeed.AsyncPaginated never fires. ObviouslyGetDataAsync
never runs, so no data displays.If I encapsulate the ListView inside a FeedView as below, it displays a first page fine, so the binding works.
Why would this super simple example fail to work. Is the Listview not designed to work with a ListFeed?
Help shall be much appreciated.
The sample project is at: https://github.com/hbraasch/UnoPaginateTester.git
Thanks
Beta Was this translation helpful? Give feedback.
All reactions