From 0462ed8df1d85cb4aa897f783c82ed6196a418f5 Mon Sep 17 00:00:00 2001 From: Jonas Kamsker Date: Wed, 17 May 2023 11:27:34 +0200 Subject: [PATCH 1/2] Added property changing handling into listprompt --- src/Spectre.Console/Prompts/List/ListPrompt.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Spectre.Console/Prompts/List/ListPrompt.cs b/src/Spectre.Console/Prompts/List/ListPrompt.cs index f30f4d348..b0fb25510 100644 --- a/src/Spectre.Console/Prompts/List/ListPrompt.cs +++ b/src/Spectre.Console/Prompts/List/ListPrompt.cs @@ -43,6 +43,18 @@ public ListPrompt(IAnsiConsole console, IListPromptStrategy strategy) using (new RenderHookScope(_console, hook)) { + Action disposal = default; + foreach (var item in tree.Traverse()) + { + if (!(item.Data is INotifyPropertyChanged npc)) + { + continue; + } + + npc.PropertyChanged += (sender, args) => hook.Refresh(); + disposal += () => npc.PropertyChanged -= (sender, args) => hook.Refresh(); + } + _console.Cursor.Hide(); hook.Refresh(); @@ -66,6 +78,8 @@ public ListPrompt(IAnsiConsole console, IListPromptStrategy strategy) hook.Refresh(); } } + + disposal?.Invoke(); } hook.Clear(); From 39053f47b7d5b655796a9db5e2efff89150db567 Mon Sep 17 00:00:00 2001 From: Jonas Kamsker Date: Wed, 17 May 2023 11:35:11 +0200 Subject: [PATCH 2/2] Delegates are usually okay with being null and then += anything :/ --- src/Spectre.Console/Prompts/List/ListPrompt.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Spectre.Console/Prompts/List/ListPrompt.cs b/src/Spectre.Console/Prompts/List/ListPrompt.cs index b0fb25510..f83bb99f2 100644 --- a/src/Spectre.Console/Prompts/List/ListPrompt.cs +++ b/src/Spectre.Console/Prompts/List/ListPrompt.cs @@ -43,7 +43,7 @@ public ListPrompt(IAnsiConsole console, IListPromptStrategy strategy) using (new RenderHookScope(_console, hook)) { - Action disposal = default; + Action disposal = () => { }; foreach (var item in tree.Traverse()) { if (!(item.Data is INotifyPropertyChanged npc))