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

Cant seem to get a binding to work (BooleanToObjectConverter and ImageResourceExtention).

$
0
0

Hello everyone.
I have been following https://blog.xamarin.com/behaviors-in-xamarin-forms/ and the referenced material on git to recreate the email checkmark.
While the EmailValidatorBehaviour seems to work, there is no image appearing. ( I looked at https://developer.xamarin.com/guides/xamarin-forms/user-interface/images/#Embedded_Images to be sure)
When I put breakpoints in the BooleanToObjectConverter and ImageResourceExtention classes, they dont get hit. (Only when the app is launched, when the xaml is initialized.)
I put the xaml code below.
The experience I have with Xamarin and C# is limited. However I have programmed for many years.~~~~

Can someone point me into the right direction?
Thanks in advance.

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:HanzeStudentX;assembly=HanzeStudentX"
             xmlns:conv="clr-namespace:HanzeStudentX.Util.Converters"
             xmlns:img="clr-namespace:HanzeStudentX.Util.Extentions"
             xmlns:beh="clr-namespace:HanzeStudentX.Util.Behaviours"
             x:Class="HanzeStudentX.MainPage"
             BackgroundColor="Orange">
    <ContentPage.Resources>
        <ResourceDictionary>
            <conv:BooleanToObjectConverter x:Key="boolToStyleImage" x:TypeArguments="Style">
                <conv:BooleanToObjectConverter.FalseObject>
                    <Style TargetType="Image">
                        <Setter Property="Source" Value="{img:ImageResource HanzeStudentX.Images.Isuccess.png}" />
                    </Style>
                </conv:BooleanToObjectConverter.FalseObject>

                <conv:BooleanToObjectConverter.TrueObject>
                    <Style TargetType="Image">
                        <Setter Property="Source" Value="{img:ImageResource HanzeStudentX.Images.success.png}" />
                    </Style>
                </conv:BooleanToObjectConverter.TrueObject>
            </conv:BooleanToObjectConverter>
        </ResourceDictionary>
    </ContentPage.Resources>
<Grid  VerticalOptions="FillAndExpand">
        <Grid.RowDefinitions>
            <RowDefinition Height="2*"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="2*"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="10"/>
            <ColumnDefinition Width="3*" />
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="10" />
        </Grid.ColumnDefinitions>
        <Label
            HorizontalOptions="Center"
            Grid.Row="0"
            Grid.Column="1"
            Grid.ColumnSpan="2"
            FontAttributes="Bold"
            Text="HanzeStudent"
            FontSize="Large"
            />
        <Entry 
            Grid.Row="1" 
            Grid.Column="1" 
            x:Name="studentemailfield"  
            Placeholder="Student Email" 
            HorizontalOptions="Fill" 
            BackgroundColor="White" 
            TextColor="Black" >
            <Entry.Behaviors>
                <beh:EmailValidatorBehavior x:Name="emailValidator" />
            </Entry.Behaviors>
        </Entry>
        <Image
            Grid.Row="1"
            Grid.Column="2"
            x:Name="emailSuccessErrorImage"
            Style="{Binding Source={x:Reference emailValidator}, Path=IsValid, Converter={StaticResource boolToStyleImage}}"

            />
        <Entry 
            Grid.Row="2" 
            Grid.Column="1" 
            x:Name="passwordfield" 
            Placeholder="Password" 
            IsPassword="true" 
            HorizontalOptions="Fill" 
            BackgroundColor="White"  
            TextColor="Black"/>
        <ActivityIndicator  
            Grid.Row="2" 
            Grid.Column="2" 
            Color="White"
            x:Name="loginactivityindicator"
            HorizontalOptions="Center" 
            VerticalOptions="Center"/>
        <Button 
            Grid.Row="3"
            Grid.Column="1"
            Grid.ColumnSpan="2"
            x:Name="loginbutton"
            Text="Login"
            TextColor="Black"
            BackgroundColor="Red"
            BorderColor="White"
            Clicked="Button_Clicked" />
    </Grid>
</ContentPage>

Viewing all articles
Browse latest Browse all 91519

Trending Articles



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