Created
June 18, 2016 07:41
-
-
Save rohits79/594a6e1d26527ecc679d08a74bef255c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SomeViewModel : INotifyPropertyChanged, INotifyDataErrorInfo | |
{ | |
errorsContainer = new ErrorsContainer<string>(x => ErrorsChanged?.Invoke(this, new DataErrorsChangedEventArgs(x))); | |
public IEnumerable GetErrors(string propertyName) | |
{ | |
return errorsContainer.GetErrors(propertyName); | |
} | |
private string propertyName; | |
public string PropertyName | |
{ | |
get | |
{ | |
return propertyName; | |
} | |
set | |
{ | |
propertyName = value; | |
OnPropertyChanged(); | |
} | |
} | |
private void Validate() | |
{ | |
if(!someValidationLogic) | |
{ | |
errorsContainer.SetErrors(()=> PropertyName, new List<string>(){"Wrong Value"}); | |
} | |
else | |
{ | |
errorsContainer.ClearErrors(() => PropertyName); | |
} | |
} | |
public bool HasErrors => errorsContainer.HasErrors; | |
public event EventHandler<DataErrorsChangedEventArgs> ErrorsChanged; | |
[NotifyPropertyChangedInvocator] | |
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) | |
{ | |
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment