How can use Behaviors in code behind in xamrin form

i am new in Xamarin , i have a question about using behaviors in code behind
i use these code in Xaml and it works fine but i don't know how can i create entry and label in code behind and attach the behaviors to them like Xaml

      <StackLayout ">
            <Entry
                Text="{Binding Title}"
                HorizontalOptions="FillAndExpand"
                HeightRequest="40"
                BackgroundColor="{ DynamicResource PlaceholderColorEntry }"
                PlaceholderColor="{ DynamicResource BaseTextColor }">

                <Entry.Behaviors>
                     <validators:EntryEmptyValidatorBehavior x:Name="titleValidator"/>
                </Entry.Behaviors>

            </Entry>            
        </StackLayout>

        <StackLayout Grid.Row="1" Grid.Column="1" >
            <Label HorizontalOptions="Center" >
                    <Label.Triggers>
                        <DataTrigger TargetType="Label"  Binding="{Binding Source={x:Reference titleValidator},Path=IsValid}" Value="False">
                            <Setter Property="Text" Value="{ x:Static fontAwesome:FontAwesomeFont.ExclamationCircle }" />
                            <Setter Property="TextColor" Value="Red" />
                        </DataTrigger>
                        <DataTrigger TargetType="Label"  Binding="{Binding Source={x:Reference titleValidator},Path=IsValid}" Value="True">
                            <Setter Property="Text" Value="{ x:Static fontAwesome:FontAwesomeFont.CheckCircle }" />
                            <Setter Property="TextColor" Value="Green" />                                   
                        </DataTrigger>
                    </Label.Triggers>
             </Label>
        </StackLayout>

Best Answers

Answers

Sign In or Register to comment.