Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 91519

Bind image to email validator boolean

$
0
0

I'm trying to replicate the email validator behavior in c# and, being the rookie that I am, have had trouble making sense of the XAML example to use in my c# page. I can't figure out how to bind an image to the isValid boolean behavior on my email entry. Has anyone done something similar already in c#?

My code currently looks like this:

var eEmail = new Entry
                 {
                     Text = selectedUser.email,
                     WidthRequest = 200,
                     VerticalOptions = LayoutOptions.CenterAndExpand,
                     HorizontalOptions = LayoutOptions.CenterAndExpand
                     //Behaviors.Add(new EmailValidationBehavior)
                 };
       eEmail.Behaviors.Add(new EmailValidationBehavior());

var iInvalidEmail = new Image();

Here is the XAML example:

<local:BooleanToObjectConverter x:Key="boolToStyleImage"
                                          x:TypeArguments="Style">
    <local:BooleanToObjectConverter.FalseObject>
      <Style TargetType="Image">
        <Setter Property="HeightRequest" Value="20" />
        <Setter Property="Source" Value="{local:ImageResource Samples.Images.error.png}" />
      </Style>
    </local:BooleanToObjectConverter.FalseObject>

    <local:BooleanToObjectConverter x:Key="boolToStyleEmail"
                                       x:TypeArguments="Style">
    <local:BooleanToObjectConverter.FalseObject>
       <Style TargetType="Label" BasedOn="{StaticResource baseStyle}">
        <Setter Property="TextColor" Value="#F44336" />
        <Setter Property="Text" Value="Enter a valid email" />
      </Style>
    </local:BooleanToObjectConverter.FalseObject>

Viewing all articles
Browse latest Browse all 91519

Trending Articles



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