Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Bindable Properties

$
0
0

I have this Behavior I would set a label when the regex is match, my regex works fine, the color on entry change.
But for the label i would set, I don't know how use the bindable properties.

behavior.cs

 const string labelDefault = "Email isn't correct, please modify";
 const string labelValid = "Email is correct, please connect you";

static readonly BindablePropertyKey isValidLabel = BindableProperty.CreateReadOnly("IsValidLabel", typeof(string), typeof(LoginBehavior), labelDefault);

        public static readonly BindableProperty IsValidProperty = isValidLabel.BindableProperty;

        public string IsValidLabel
        {
            get { return (string)GetValue(IsValidProperty); }
            private set { SetValue(isValidLabel, value); }
        }

void OnEntryTextChanged(object sender, TextChangedEventArgs args)
        {
            Regex regex = new Regex(emailRegex);
            bool isValid = regex.IsMatch(args.NewTextValue);
            ((Entry)sender).TextColor = isValid ? Color.Default : Color.Red;
            this.IsValidLabel = labelValid;

        }

view.xaml

<StackLayout Padding="15">
                <Image Source="dose_landauer.png"/>
                <Label Text="Login"/>
                <Entry Text="{Binding User.Username}"
                       Placeholder="Username" x:Name="entryUsernameConnection">
                    <Entry.Behaviors>
                        <behavior:LoginBehavior/>
                    </Entry.Behaviors>
                </Entry>
                <Label Text="Password"/>
                <Entry Text="{Binding User.Password}"
                       Placeholder="Password"
                       IsPassword="True" x:Name="entryPwdConnection">
                </Entry>
                <Label Text="{Binding IsValidProperty}">
                </Label>
                <Button Text="Login" Command="{Binding ClickLogin}"/>
            </StackLayout>

Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>