Skip to content

Instantly share code, notes, and snippets.

@ameerthehacker
Last active August 25, 2018 15:50
Show Gist options
  • Save ameerthehacker/1bdcd04385d14c45d641bd56d4a01fb8 to your computer and use it in GitHub Desktop.
Save ameerthehacker/1bdcd04385d14c45d641bd56d4a01fb8 to your computer and use it in GitHub Desktop.
...
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