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.