Last active
August 25, 2018 15:50
-
-
Save ameerthehacker/1bdcd04385d14c45d641bd56d4a01fb8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
... | |
namespace XamarinFormValidation.Behaviors | |
{ | |
public class ValidationBehavior : Behavior<View> | |
{ | |
... | |
public bool Validate() | |
{ | |
bool isValid = true; | |
string errorMessage = ""; | |
foreach (IValidator validator in Validators) | |
{ | |
bool result = validator.Check(_view.GetType() | |
.GetProperty(PropertyName) | |
.GetValue(_view) as string); | |
isValid = isValid && result; | |
if (!result) | |
{ | |
errorMessage = validator.Message; | |
break; | |
} | |
} | |
if (!isValid) | |
{ | |
_style.ShowError(_view, errorMessage); | |
return false; | |
} | |
else | |
{ | |
_style.RemoveError(_view); | |
return true; | |
} | |
} | |
... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment