Created
October 26, 2017 22:37
-
-
Save Char0394/0fcd4d371ef3f3adaf063e03c3c286af 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
| public class EmptyEntryValidatorBehavior : Behavior<ExtendedEntry> | |
| { | |
| ExtendedEntry control; | |
| string _placeHolder; | |
| Xamarin.Forms.Color _placeHolderColor; | |
| protected override void OnAttachedTo(ExtendedEntry bindable) | |
| { | |
| bindable.TextChanged += HandleTextChanged; | |
| bindable.PropertyChanged += OnPropertyChanged; | |
| control = bindable; | |
| _placeHolder = bindable.Placeholder; | |
| _placeHolderColor = bindable.PlaceholderColor; | |
| } | |
| void HandleTextChanged(object sender, TextChangedEventArgs e) | |
| { | |
| if (!string.IsNullOrEmpty(e.NewTextValue)) | |
| { | |
| ((ExtendedEntry)sender).IsBorderErrorVisible = false; | |
| } | |
| } | |
| protected override void OnDetachingFrom(ExtendedEntry bindable) | |
| { | |
| bindable.TextChanged -= HandleTextChanged; | |
| bindable.PropertyChanged -= OnPropertyChanged; | |
| } | |
| void OnPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) | |
| { | |
| if (e.PropertyName == ExtendedEntry.IsBorderErrorVisibleProperty.PropertyName && control != null) | |
| { | |
| if (control.IsBorderErrorVisible) | |
| { | |
| control.Placeholder = control.ErrorText; | |
| control.PlaceholderColor = control.BorderErrorColor; | |
| control.Text = string.Empty; | |
| } | |
| else{ | |
| control.Placeholder = _placeHolder; | |
| control.PlaceholderColor = _placeHolderColor; | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment