From c2084b6cd113bfaa7a6c26c570ba70664b6d54c2 Mon Sep 17 00:00:00 2001 From: TongTongStudio Date: Sat, 28 Nov 2026 05:37:39 +0800 Subject: [PATCH] Handle null content when recycling Emulator table rows --- MainWindow.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/MainWindow.cs b/MainWindow.cs index a41aa69..a53a96b 100644 --- a/MainWindow.cs +++ b/MainWindow.cs @@ -185,6 +185,9 @@ internal sealed class MainWindow : Window { try { + // Recycling a visible row asks its template to build null content. + instances.ItemTemplate?.Build(null); + images.ItemTemplate?.Build(null); using var timeout = new CancellationTokenSource(TimeSpan.FromSeconds(20)); await RefreshInstances(timeout.Token); await RefreshImages(timeout.Token, true); @@ -194,7 +197,7 @@ internal sealed class MainWindow : Window catch (Exception error) { Console.Error.WriteLine(error); - shutdown(1); + Dispatcher.UIThread.Post(() => shutdown(1)); } }; } @@ -396,7 +399,9 @@ internal sealed class MainWindow : Window private static Control Table(ListBox list, string columns, string[] headings, Func cells) where T : class { - list.ItemTemplate = new FuncDataTemplate((item, _) => TableRow(columns, cells(item!), false)); + // Avalonia clears the content to null before reusing a virtualized row. + list.ItemTemplate = new FuncDataTemplate((item, _) => + item is null ? null : TableRow(columns, cells(item), false)); list.Padding = new Thickness(0); var panel = new DockPanel(); var header = new Border