diff options
author | Eric Maupin <ermaup@microsoft.com> | 2019-02-05 21:50:02 +0300 |
---|---|---|
committer | Eric Maupin <ermaup@microsoft.com> | 2019-02-15 21:00:44 +0300 |
commit | 687934e61ad8db63cd62d6b1e2df0988204e7c21 (patch) | |
tree | ab4fdf2d18ccd4c5865339b391cadf86dd7f4e26 /Xamarin.PropertyEditing | |
parent | 6a6761eb9b3d8624ee6901fcde1c94db47250357 (diff) |
[Core] Ensure new object reuses view models
Diffstat (limited to 'Xamarin.PropertyEditing')
-rw-r--r-- | Xamarin.PropertyEditing/Extensions.cs | 15 | ||||
-rw-r--r-- | Xamarin.PropertyEditing/ViewModels/ObjectPropertyViewModel.cs | 9 |
2 files changed, 21 insertions, 3 deletions
diff --git a/Xamarin.PropertyEditing/Extensions.cs b/Xamarin.PropertyEditing/Extensions.cs index 333f0e8..0619096 100644 --- a/Xamarin.PropertyEditing/Extensions.cs +++ b/Xamarin.PropertyEditing/Extensions.cs @@ -107,6 +107,21 @@ namespace Xamarin.PropertyEditing self.Add (with); } + public static void Reset<T> (this ICollection<T> self, IEnumerable<T> newContents) + { + if (self == null) + throw new ArgumentNullException (nameof(self)); + if (newContents == null) + throw new ArgumentNullException (nameof(newContents)); + + if (self is ObservableCollectionEx<T> oce) { + oce.Reset (newContents); + } else { + self.Clear(); + self.AddItems (newContents); + } + } + public static void Move (this IList self, int index, int moveTo) { if (self == null) diff --git a/Xamarin.PropertyEditing/ViewModels/ObjectPropertyViewModel.cs b/Xamarin.PropertyEditing/ViewModels/ObjectPropertyViewModel.cs index 56192e1..4e8b91d 100644 --- a/Xamarin.PropertyEditing/ViewModels/ObjectPropertyViewModel.cs +++ b/Xamarin.PropertyEditing/ViewModels/ObjectPropertyViewModel.cs @@ -90,13 +90,16 @@ namespace Xamarin.PropertyEditing.ViewModels return; using (await AsyncWork.RequestAsyncWork (this)) { - ValueModel.SelectedObjects.Clear(); + await base.UpdateCurrentValueAsync (); ValueType = CurrentValue?.ValueDescriptor as ITypeInfo; - if (CurrentValue?.Value != null) - ValueModel.SelectedObjects.Add (CurrentValue.Value); + if (CurrentValue?.Value != null) { + ValueModel.SelectedObjects.Reset (new[] { CurrentValue.Value }); + } else { + ValueModel.SelectedObjects.Clear (); + } SetCanDelve (ValueModel.SelectedObjects.Count > 0); } |