diff options
author | Eric Maupin <ermaup@microsoft.com> | 2018-08-31 22:38:18 +0300 |
---|---|---|
committer | Eric Maupin <ermaup@microsoft.com> | 2018-08-31 22:38:22 +0300 |
commit | 537e3372ebdf61b3490d848b5c45fa4b5ed982b0 (patch) | |
tree | b01cc860322212b435a40641c5920d4199644fdc | |
parent | 738949a696525c3166ef8da269f522b525fdcc19 (diff) |
[Core] Handle no-editors in CollectionPropertyViewModel
Fixes #294
-rw-r--r-- | Xamarin.PropertyEditing.Tests/CollectionPropertyViewModelTests.cs | 22 | ||||
-rw-r--r-- | Xamarin.PropertyEditing/ViewModels/CollectionPropertyViewModel.cs | 9 |
2 files changed, 31 insertions, 0 deletions
diff --git a/Xamarin.PropertyEditing.Tests/CollectionPropertyViewModelTests.cs b/Xamarin.PropertyEditing.Tests/CollectionPropertyViewModelTests.cs index 0139aad..7f87448 100644 --- a/Xamarin.PropertyEditing.Tests/CollectionPropertyViewModelTests.cs +++ b/Xamarin.PropertyEditing.Tests/CollectionPropertyViewModelTests.cs @@ -158,6 +158,28 @@ namespace Xamarin.PropertyEditing.Tests } [Test] + public async Task RemoveEditor () + { + TargetPlatform platform = new TargetPlatform (new MockEditorProvider ()); + + var obj = new { + Collection = new ArrayList () + }; + + var editor = new ReflectionObjectEditor (obj); + + var vm = new CollectionPropertyViewModel (platform, editor.Properties.First (), new[] { editor }); + await vm.AssignableTypes.Task; + + vm.Editors.Remove (editor); + await vm.AssignableTypes.Task; + + Assert.That (vm.AssignableTypes.Value, Is.Empty); + Assert.That (vm.SuggestedTypes, Is.Empty); + Assert.That (vm.SelectedType, Is.Null); + } + + [Test] public async Task MoveUpCommand () { TargetPlatform platform = new TargetPlatform (new MockEditorProvider()); diff --git a/Xamarin.PropertyEditing/ViewModels/CollectionPropertyViewModel.cs b/Xamarin.PropertyEditing/ViewModels/CollectionPropertyViewModel.cs index 641e19e..080a93a 100644 --- a/Xamarin.PropertyEditing/ViewModels/CollectionPropertyViewModel.cs +++ b/Xamarin.PropertyEditing/ViewModels/CollectionPropertyViewModel.cs @@ -317,6 +317,15 @@ namespace Xamarin.PropertyEditing.ViewModels if (Property == null) return; + if (Editors.Count == 0) { + SuggestedTypes = new ObservableCollectionEx<ITypeInfo> (); + AssignableTypes = new AsyncValue<IReadOnlyDictionary<IAssemblyInfo, ILookup<string, ITypeInfo>>> ( + Task.FromResult<IReadOnlyDictionary<IAssemblyInfo, ILookup<string, ITypeInfo>>> ( + new Dictionary<IAssemblyInfo, ILookup<string, ITypeInfo>> ())); + SelectedType = null; + return; + } + var types = Editors.GetCommonAssignableTypes (Property, childTypes: true); var assignableTypesTask = types.ContinueWith (t => t.Result.GetTypeTree (), TaskScheduler.Default); AssignableTypes = new AsyncValue<IReadOnlyDictionary<IAssemblyInfo, ILookup<string, ITypeInfo>>> (assignableTypesTask); |