Xamarin.Forms: Validation using Behaviors

public class HolderNameValidation : Behavior
        protected override void OnAttachedTo(Entry bindable)
            bindable.TextChanged += OnInput;

        protected override void OnDetachingFrom(Entry bindable)
            bindable.TextChanged -= OnInput;

        void OnInput(object sender, TextChangedEventArgs e)
            var bindable = sender as Entry;

            var firstName = parseFirstName(e.NewTextValue);
            var lastName =  parseLastName (e.NewTextValue);

            if (firstName.Item == "" || lastName.Item == "")
                 bindable.BackgroundColor = Theme.InvalidEntryColor;
            else bindable.BackgroundColor = Theme.ValidatedEntryColor;



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: