Handle null content when recycling Emulator table rows

This commit is contained in:
tongtong committed 2026-11-28 05:37:39 +08:00
1 parent f32ecf35d5
commit c2084b6cd1
1 file changed
+7 -2
+7 -2
View File
@@ -185,6 +185,9 @@ internal sealed class MainWindow : Window
{ {
try 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)); using var timeout = new CancellationTokenSource(TimeSpan.FromSeconds(20));
await RefreshInstances(timeout.Token); await RefreshInstances(timeout.Token);
await RefreshImages(timeout.Token, true); await RefreshImages(timeout.Token, true);
@@ -194,7 +197,7 @@ internal sealed class MainWindow : Window
catch (Exception error) catch (Exception error)
{ {
Console.Error.WriteLine(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<T>(ListBox list, string columns, string[] headings, Func<T, string[]> cells) private static Control Table<T>(ListBox list, string columns, string[] headings, Func<T, string[]> cells)
where T : class where T : class
{ {
list.ItemTemplate = new FuncDataTemplate<T>((item, _) => TableRow(columns, cells(item!), false)); // Avalonia clears the content to null before reusing a virtualized row.
list.ItemTemplate = new FuncDataTemplate<T>((item, _) =>
item is null ? null : TableRow(columns, cells(item), false));
list.Padding = new Thickness(0); list.Padding = new Thickness(0);
var panel = new DockPanel(); var panel = new DockPanel();
var header = new Border var header = new Border