diff options
author | Eric Maupin <ermaup@microsoft.com> | 2018-03-15 23:22:14 +0300 |
---|---|---|
committer | Eric Maupin <ermaup@microsoft.com> | 2018-03-15 23:22:14 +0300 |
commit | 2e02e318b90c81bcb17b1d70ac81cc70c7fd792a (patch) | |
tree | 670024866c53b3524137694373352f4cf1c5c589 /Xamarin.PropertyEditing | |
parent | c5c47698d5e2ff5076691c4e2da7b2a337267105 (diff) |
[Core] Add base level validation
Diffstat (limited to 'Xamarin.PropertyEditing')
-rw-r--r-- | Xamarin.PropertyEditing/ViewModels/PropertyViewModel.cs | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/Xamarin.PropertyEditing/ViewModels/PropertyViewModel.cs b/Xamarin.PropertyEditing/ViewModels/PropertyViewModel.cs index 593d13e..758cb5e 100644 --- a/Xamarin.PropertyEditing/ViewModels/PropertyViewModel.cs +++ b/Xamarin.PropertyEditing/ViewModels/PropertyViewModel.cs @@ -24,6 +24,7 @@ namespace Xamarin.PropertyEditing.ViewModels : base (platform, property, editors) { this.coerce = property as ICoerce<TValue>; + this.validator = property as IValidator<TValue>; this.isNullable = (!property.ValueSources.HasFlag (ValueSources.Default) || property.Type.Name == NullableName); SetValueResourceCommand = new RelayCommand<Resource> (OnSetValueToResource, CanSetValueToResource); @@ -153,6 +154,12 @@ namespace Xamarin.PropertyEditing.ViewModels SetError (null); + // We may need to be more careful about value sources here + if (this.validator != null && !this.validator.IsValid (newValue.Value)) { + SignalValueChange(); // Ensure UI refresh its own value + return; + } + using (await AsyncWork.RequestAsyncWork (this)) { try { Task[] setValues = new Task[Editors.Count]; @@ -177,10 +184,19 @@ namespace Xamarin.PropertyEditing.ViewModels } private readonly ICoerce<TValue> coerce; + private readonly IValidator<TValue> validator; private const string NullableName = "Nullable`1"; private bool isNullable; private ValueInfo<TValue> value; + private void SignalValueChange () + { + OnPropertyChanged (nameof (Value)); + OnPropertyChanged (nameof (ValueSource)); + OnPropertyChanged (nameof (CustomExpression)); + OnPropertyChanged (nameof (Resource)); + } + private bool SetCurrentValue (ValueInfo<TValue> newValue) { if (!this.isNullable && newValue != null && newValue.Value == null) @@ -191,10 +207,7 @@ namespace Xamarin.PropertyEditing.ViewModels this.value = newValue; OnValueChanged (); - OnPropertyChanged (nameof (Value)); - OnPropertyChanged (nameof (ValueSource)); - OnPropertyChanged (nameof (CustomExpression)); - OnPropertyChanged (nameof (Resource)); + SignalValueChange(); ((RelayCommand) ClearValueCommand)?.ChangeCanExecute (); |