Last active
August 25, 2018 15:49
-
-
Save ameerthehacker/4536e13fd8042ae3c7c4100c4a1e04bb 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() | |
{ | |
... | |
} | |
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