Hi,
I've an entry for email with a behavior checking if the field is correct.
In XAML is:
<inputLayout:SfTextInputLayout ContainerType="Outlined" Hint="Indirizzo Email" ErrorText="L'indirizzo email non è valido">
<Entry TextColor="White" Text="{Binding Email}" Keyboard="Email" IsVisible="{Binding IsNotPartner}" >
<Entry.Behaviors>
<local:EmailValitationBehavior />
</Entry.Behaviors>
</Entry>
</inputLayout:SfTextInputLayout>
The Behavior is:
public class EmailValitationBehavior : Behavior<Entry>
{
const string emailRegex = @"^(?("")("".+?(?<!\\)""@)|(([0-9a-z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-z])@))" +
@"(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-z][-\w]*[0-9a-z]*\.)+[a-z0-9][\-a-z0-9]{0,22}[a-z0-9]))$";
protected override void OnAttachedTo(Entry bindable)
{
bindable.Unfocused += HandleCompleted;
base.OnAttachedTo(bindable);
}
void HandleCompleted(object sender, EventArgs e)
{
Entry s = (Entry)sender;
bool IsValid = (Regex.IsMatch(s.Text, emailRegex, RegexOptions.IgnoreCase, TimeSpan.FromMilliseconds(250)));
s.TextColor = IsValid ? Color.Blue : Color.Red;
(s.Parent as SfTextInputLayout).HasError = IsValid ? false : true;
}
protected override void OnDetachingFrom(Entry bindable)
{
bindable.Unfocused -= HandleCompleted;
base.OnDetachingFrom(bindable);
}
}
I've tryied to set the HasError of the Parent of Entry, but its doesn't work.
How to do that in a MVVM environment (PRISM)?
Thanks a lot and have a nice day,
Andrea