Repository navigation
Description
Current behavior
With ListFeed.PaginatedAsync(...).Selection(state) shown in a FeedView, refreshing the feed (FeedView.Refresh) clears the ListView's selection while the model's selection state keeps the item. The selected item is in the reloaded first page, and it is the same ListView instance; the template is not re-applied. Loading the next page afterwards doesn't restore it either.
Output of the self-testing repro below, the same in 3 runs out of 3:
REPRO 1. Item 7 selected in the ListView: ListView.SelectedItem=Item 7; model Selected=Item 7; items=20; ListView instances=1
REPRO 2. after FeedView.Refresh (Item 7 is in the reloaded first page): ListView.SelectedItem=<none>; model Selected=Item 7; items=20; ListView instances=1
REPRO 3. after the next page loaded: ListView.SelectedItem=<none>; model Selected=Item 7; items=40; ListView instances=1
So after a refresh the UI shows no selected row while the detail bound to the state still shows the item.
Expected behavior
After a refresh, an item that is still in the list stays selected in the ListView, matching the selection state. ListFeedSelection matches the selected item by entity key in each new list, and the state does keep it, but the view isn't told.
How to reproduce it (as minimally and precisely as possible)
dotnet new unoapp -preset recommended -platforms desktop -n SelRepro(Uno.Templates 7.0.0-dev.81).- Replace
Presentation/MainModel.cs,MainPage.xamlandMainPage.xaml.cswith the files below. dotnet run -f net10.0-desktop. The page selects the 7th row throughListView.SelectedIndex(as a click would), executesFeedView.Refresh, scrolls to load the next page, prints theListView's and the model's selection after each step, and exits.
Presentation/MainModel.cs
namespace SelRepro.Presentation;
public partial record Item(string Id, string Name);
public partial record MainModel
{
// The pattern from the uno-mvux skill's selection reference, on a paginated feed.
public IListFeed<Item> Items => ListFeed
.PaginatedAsync(LoadAsync)
.Selection(Selected);
public IState<Item> Selected => State<Item>.Empty(this);
// 200 items, 20 per page.
private static async ValueTask<IImmutableList<Item>> LoadAsync(PageRequest request, CancellationToken ct)
{
await Task.Delay(300, ct);
var start = (int)request.CurrentCount;
return Enumerable.Range(start, Math.Max(0, Math.Min(20, 200 - start)))
.Select(i => new Item($"I-{i + 1:000}", $"Item {i + 1}"))
.ToImmutableList();
}
}Presentation/MainPage.xaml
<Page x:Class="SelRepro.Presentation.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mvux="using:Uno.Extensions.Reactive.UI"
NavigationCacheMode="Required"
Background="{ThemeResource BackgroundBrush}">
<Grid RowDefinitions="Auto,*" Padding="12" RowSpacing="12">
<StackPanel Orientation="Horizontal" Spacing="12">
<Button Content="Refresh" Command="{Binding Refresh, ElementName=ItemsFeedView}" />
<TextBlock Text="Selected (model):" VerticalAlignment="Center" />
<TextBlock x:Name="ModelSelected" Text="{Binding Selected.Name}" VerticalAlignment="Center" />
</StackPanel>
<mvux:FeedView x:Name="ItemsFeedView" Grid.Row="1" Source="{Binding Items}" RefreshingState="None">
<mvux:FeedView.ValueTemplate>
<DataTemplate>
<ListView ItemsSource="{Binding Data}" SelectionMode="Single" Loaded="OnListLoaded">
<ListView.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</DataTemplate>
</mvux:FeedView.ValueTemplate>
</mvux:FeedView>
</Grid>
</Page>Presentation/MainPage.xaml.cs
namespace SelRepro.Presentation;
// Self-test: select a row as a user would (ListView.SelectedIndex), refresh through FeedView.Refresh,
// load the next page, and print the ListView's and the model's selection after each step.
public sealed partial class MainPage : Page
{
private ListView? _list;
private int _listInstances;
public MainPage()
{
this.InitializeComponent();
Loaded += async (_, _) => await RunAsync();
}
private void OnListLoaded(object sender, RoutedEventArgs e)
{
_list = (ListView)sender;
_listInstances++;
}
private async Task RunAsync()
{
try
{
await Until(() => _list is { Items.Count: >= 20 }, "the first page");
Report("0. first page loaded");
_list!.SelectedIndex = 6;
await Task.Delay(1000);
Report("1. Item 7 selected in the ListView");
ItemsFeedView.Refresh.Execute(null);
await Task.Delay(3000);
Report("2. after FeedView.Refresh (Item 7 is in the reloaded first page)");
_list!.ScrollIntoView(_list.Items[_list.Items.Count - 1]);
await Until(() => _list.Items.Count >= 40, "the second page");
await Task.Delay(1000);
Report("3. after the next page loaded");
}
catch (Exception ex)
{
Console.WriteLine($"REPRO error: {ex}");
}
finally
{
Application.Current.Exit();
}
}
private void Report(string step)
=> Console.WriteLine($"REPRO {step}: ListView.SelectedItem={(_list?.SelectedItem as Item)?.Name ?? "<none>"}; model Selected={(string.IsNullOrEmpty(ModelSelected.Text) ? "<none>" : ModelSelected.Text)}; items={_list?.Items.Count}; ListView instances={_listInstances}");
private static async Task Until(Func<bool> condition, string what)
{
for (var i = 0; i < 150 && !condition(); i++)
{
await Task.Delay(100);
}
if (!condition())
{
throw new TimeoutException($"Timed out waiting for {what}.");
}
}
}Environment
Nuget Package (s): Uno.Extensions.Reactive, Uno.Extensions.Reactive.WinUI (via Uno.Sdk, MVUX feature)
Package Version(s): Uno.Extensions.Reactive 8.0.0-dev.101, Uno.WinUI 7.0.0-dev.2347, Uno.Sdk 7.0.0-dev.81, .NET SDK 10.0.400
Affected platform(s):
- Skia desktop (
net10.0-desktop) on Windows 11. Other platforms not checked.
Anything else we need to know?
Found by AI agents building a paged list with a selected-item detail from the uno-mvux skill's selection pattern: in both sessions the agent hit this. One added code-behind that re-selects the row after every reload. The other removed .Selection(...) entirely and handled SelectionChanged itself, after its workarounds led the ListView to write null back into the state while paging. Possibly the same model-to-view gap as #2946.
Activity
fix(reactive): keep the selection made on the list of a ListFeed.Sele…
fix(reactive): do not push the selection cleared by the ListView on a…
docs(specs): 019 progress for the MVUX selection lost on refresh and …