Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/xamarin/Xamarin.PropertyEditing.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Maupin <ermaup@microsoft.com>2018-08-23 22:02:22 +0300
committerEric Maupin <ermaup@microsoft.com>2018-08-23 22:02:23 +0300
commit9b1d9a8b5addd6bdceb758a8039e05a88214f72b (patch)
treeedd09cc03b53a4883d2e5471f97b1b1f5512d0ba
parent96044ed481d24cb834dd27cb3ee489b5df9e94ab (diff)
[Win] Fix canceled add Value Converter
Fixes cancelling an add value converter resource not switching back to the last selected option. Also refactored a little bit to clean up names. Fixes #332
-rw-r--r--Xamarin.PropertyEditing/ViewModels/CreateBindingViewModel.cs30
1 files changed, 12 insertions, 18 deletions
diff --git a/Xamarin.PropertyEditing/ViewModels/CreateBindingViewModel.cs b/Xamarin.PropertyEditing/ViewModels/CreateBindingViewModel.cs
index 245da34..95610bb 100644
--- a/Xamarin.PropertyEditing/ViewModels/CreateBindingViewModel.cs
+++ b/Xamarin.PropertyEditing/ViewModels/CreateBindingViewModel.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
+using System.Threading;
using System.Threading.Tasks;
using Xamarin.PropertyEditing.Properties;
@@ -375,7 +376,8 @@ namespace Xamarin.PropertyEditing.ViewModels
set
{
var vm = GetKnownPropertyViewModel (PropertyBinding.ConverterProperty);
- if (vm.Value == value)
+ var previous = vm.Value;
+ if (previous == value)
return;
if (value == NoValueConverter)
@@ -385,11 +387,7 @@ namespace Xamarin.PropertyEditing.ViewModels
OnPropertyChanged();
if (value == AddValueConverter) {
- var request = RequestCreateValueConverter ();
- if (request.ConverterType != null)
- RequestCreateRequestedValueConverter (request);
- else
- SelectedValueConverter = NoValueConverter;
+ RequestCreateValueConverter (previous);
}
}
}
@@ -636,27 +634,23 @@ namespace Xamarin.PropertyEditing.ViewModels
Path = newPath;
}
- private CreateValueConverterEventArgs RequestCreateValueConverter ()
+ private async void RequestCreateValueConverter (Resource previous)
{
- var e = new CreateValueConverterEventArgs();
- CreateValueConverterRequested?.Invoke (this, e);
- return e;
- }
+ var request = new CreateValueConverterEventArgs ();
+ CreateValueConverterRequested?.Invoke (this, request);
- private async void RequestCreateRequestedValueConverter (CreateValueConverterEventArgs e)
- {
- if (e.ConverterType == null || e.Name == null) {
- SelectedValueConverter = NoValueConverter;
+ if (request.ConverterType == null || request.Name == null) {
+ SynchronizationContext.Current.Post (p => SelectedValueConverter = (Resource)p, previous);
return;
}
- object converter = await TargetPlatform.EditorProvider.CreateObjectAsync (e.ConverterType);
- if (e.Source == null) {
+ object converter = await TargetPlatform.EditorProvider.CreateObjectAsync (request.ConverterType);
+ if (request.Source == null) {
// TODO: Set directly outside of a resource
return;
}
- Resource resource = await TargetPlatform.ResourceProvider.CreateResourceAsync (e.Source, e.Name, converter);
+ Resource resource = await TargetPlatform.ResourceProvider.CreateResourceAsync (request.Source, request.Name, converter);
this.valueConverters.Insert (this.valueConverters.Count - 1, resource);
SelectedValueConverter = resource;
}