From 419f27a932f894afe0658753b301f0937074e263 Mon Sep 17 00:00:00 2001 From: TheXamlGuy Date: Fri, 12 Jul 2024 20:13:26 +0100 Subject: [PATCH] Fixed issue when locking and unlocking the same wallet --- Toolkit.Foundation/ObservableCollection.cs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/Toolkit.Foundation/ObservableCollection.cs b/Toolkit.Foundation/ObservableCollection.cs index 763ca7c..ba218c5 100644 --- a/Toolkit.Foundation/ObservableCollection.cs +++ b/Toolkit.Foundation/ObservableCollection.cs @@ -144,13 +144,22 @@ public partial class ObservableCollection : } } - public void SetSource(IList source) + private Func defaultSelectionFactory; + + public void SetSource(IList source, + Func? defaultSelectionFactory) { foreach (TItem item in source) { Add(item); } + if (defaultSelectionFactory is not null) + { + this.defaultSelectionFactory = defaultSelectionFactory; + SelectedItem = defaultSelectionFactory.Invoke(); + } + if (source is INotifyCollectionChanged observableSource) { observableSource.CollectionChanged -= SourceCollectionChanged; @@ -193,6 +202,11 @@ public partial class ObservableCollection : { Add(item); } + + if (defaultSelectionFactory is not null) + { + SelectedItem = defaultSelectionFactory.Invoke(); + } } break; } @@ -266,6 +280,8 @@ public partial class ObservableCollection : public void Reset(Action> factory, bool disposeItems = true) { + SelectedItem = default; + Clear(disposeItems); factory.Invoke(this); }