Hi,

I am an absolute beginner to Xamarin and just started to develop a small application wherein, I am not getting any idea about why the BindableProperty changes are not getting reflected inside the view model.
Presently, I have written my BindableProperty in a separate Class and the code is as follows:

public static readonly BindableProperty IsValidEntryProperty = BindableProperty.Create("IsValidEntry", typeof(bool), typeof(MaxLengthValidatorBehavior), false, BindingMode.TwoWay);

public bool IsValidEntry
{
   get { return (bool)GetValue(IsValidEntryProperty); }
   set { SetValue(IsValidEntryProperty, value); }
}

protected override void OnAttachedTo(Entry bindable)
    {
        bindable.TextChanged += HandleTextChanged;
        base.OnAttachedTo(bindable);
    }

void HandleTextChanged(object sender, TextChangedEventArgs e)
    {
        IsValidEntry = false;
        IsValidEntry = (Regex.IsMatch(e.NewTextValue, emailRegex, RegexOptions.IgnoreCase, TimeSpan.FromMilliseconds(250)));
        if (IsValidEntry)
            EmailErrorMessage = string.Empty;
        else
            EmailErrorMessage = "The email specified is incorrect";
        ((Entry)sender).TextColor = IsValidEntry ? Color.Default : Color.Red;
    }

And, the view's code is as follows:

<Entry Grid.Column="1" Placeholder="Email" Margin="3" Text="{Binding LoginEmail, Mode=TwoWay}"
               IsVisible="{Binding SelectedPhoneEmailIndex, Converter={StaticResource KMConvert}, ConverterParameter=EMAILVIS}">
   <Entry.Behaviors>
      <kmBehaviors:EmailValidatorBehavior IsValidEntry="{Binding IsValidValueEntered, Mode=TwoWay}"
                                          EmailErrorMessage="{Binding ErrorMessageForEmail, Mode=TwoWay}" />
   </Entry.Behaviors>
</Entry>

Here, the "IsValidValueEntered" property (which is, of course, present in the view model) is bound to another Label's Text property in the same view but somehow, whenever any changes are done to the "IsValidEntryProperty" BindableProperty, those changes do not hit the setter of "IsValidValueEntered" property in the view model.

Any help is appreciated.

Thanks very much indeed.

Anyone please?

Thanks for no replies guys, I solved it myself.

For your information, I just had to specify the "Source" of the Binding which goes as follows:

    <Entry Grid.Column="1" Placeholder="Email" Margin="3" Text="{Binding LoginEmail, Mode=TwoWay}"
                   IsVisible="{Binding SelectedPhoneEmailIndex, Converter={StaticResource KMConvert}, ConverterParameter=EMAILVIS}">
       <Entry.Behaviors>
          <kmBehaviors:EmailValidatorBehavior IsValidEntry="{Binding IsValidValueEntered, Mode=TwoWay, Source={StaticResource kmViewModel}}"
          EmailErrorMessage="{Binding ErrorMessageForEmail, Mode=TwoWay, Source={StaticResource kmViewModel}}"/>
       </Entry.Behaviors>
    </Entry>

And, this did the job because earlier the Text was

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.