Skip to content

Instantly share code, notes, and snippets.

@ameerthehacker
Last active August 25, 2018 15:49
Show Gist options
  • Save ameerthehacker/4536e13fd8042ae3c7c4100c4a1e04bb to your computer and use it in GitHub Desktop.
Save ameerthehacker/4536e13fd8042ae3c7c4100c4a1e04bb to your computer and use it in GitHub Desktop.
...
namespace XamarinFormValidation.Behaviors
{
public class ValidationBehavior : Behavior<View>
{
...
public bool Validate()
{
...
}
protected override void OnAttachedTo(BindableObject bindable)
{
base.OnAttachedTo(bindable);
_view = bindable as View;
_view.PropertyChanged += OnPropertyChanged;
_view.Unfocused += OnUnFocused;
}
protected override void OnDetachingFrom(BindableObject bindable)
{
base.OnDetachingFrom(bindable);
_view.PropertyChanged -= OnPropertyChanged;
_view.Unfocused -= OnUnFocused;
}
void OnUnFocused(object sender, FocusEventArgs e)
{
Validate();
}
void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == PropertyName)
{
Validate();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment