How to trigger every change in the Entry field?

This the Entry Field which the user will input the data.

    <StackLayout Grid.Row="0" Grid.Column="0" Padding="16,13,16,9">
                    <StackLayout Orientation="Horizontal" Padding="10,0">
                      <StackLayout.GestureRecognizers>
                        <TapGestureRecognizer Tapped="OnTapVINRecognizer"/>
                      </StackLayout.GestureRecognizers>
                      <local:CustomLabel x:Name="VINLabel" Text="VIN" TextColor="#3680a4" Style="{StaticResource AccordTitleStyle}"/>
                      <Image x:Name="VINImage" Source="arrow_down.png"/>
                    </StackLayout>
                    <StackLayout x:Name="VINAccordion" IsVisible="True" Padding="0,5,0,16" Spacing="10">
                      <StackLayout Spacing="0" Orientation="Horizontal">
                        <local:CustomEntry x:Name="VINText" Placeholder="17 CHARACTERS" HorizontalOptions="FillAndExpand"/>
                      </StackLayout>
                      <local:CustomLabel Style="{StaticResource AccordLabelStyle}">
                        <local:CustomLabel.Text>
                          If the motor has a VIN, enter the VIN. A VIN is the 17 character identifier recorded on most vehicles built after 1998
                        </local:CustomLabel.Text>
                      </local:CustomLabel>
                      <local:CustomButton Clicked="OnClickSearchBtn" ClassId="vin"/>
                    </StackLayout>
                  </StackLayout>

I would like to capture every time the text changes cuz I will query the local db to check if there's a data matches from what the user inputted and then display the result below the field. How am I gonna do it in xaml?

Thanks for the suggestions and help.

Answers

  • CedGabrangCedGabrang USMember ✭✭

    Hi @JenalynParagados have you tried Entry_TextChanged event?

  • JenalynParagadosJenalynParagados USMember ✭✭
    edited August 2016

    I have tried adding this
    <Entry TextChanged="Entry_TextChanged" TextColor="Black"/>
    under this line


    And have this on the cs file but nothing change. It was not showing the text i have inputted.
    var entry = new Entry();
    entry.TextChanged += Entry_TextChanged;

        void Entry_TextChanged(object sender, TextChangedEventArgs e)
                {
                    var oldText = e.OldTextValue;
                    var newText = e.NewTextValue;
                }
    
  • NMackayNMackay GBInsider, University mod
    edited August 2016

    @JenalynParagados

    I would recommend using behaviors if your writing a XAML MVVM app.

                <Entry x:Name="EntrySearchTerm"
                                                    Grid.Column="0"
                                                    Text="{Binding SearchTerm}"
                                                    Placeholder="Name (min 2 chars)"
                                                    MinimumHeightRequest="38"
                                                    VerticalOptions="Center"
                                                    HorizontalOptions="FillAndExpand">
    
                                <custom:CustomDoneEntry.Behaviors>
                                    <b:EventHandlerBehavior EventName="TextChanged">
                                        <b:InvokeCommandAction Command="{Binding SearchCommand}" />
                                    </b:EventHandlerBehavior>
                                </custom:CustomDoneEntry.Behaviors>
    
                            </Entry>
    

    I use this library but also check out corcav behaviors

    https://www.nuget.org/packages/Behaviors.Forms/

  • CedGabrangCedGabrang USMember ✭✭
    edited August 2016
  • batmacibatmaci DEMember ✭✭✭✭✭

    @NMackay said:
    @JenalynParagados

    I would recommend using behaviors if your writing a XAML MVVM app.

              <Entry x:Name="EntrySearchTerm"
                                                    Grid.Column="0"
                                                    Text="{Binding SearchTerm}"
                                                    Placeholder="Name (min 2 chars)"
                                                    MinimumHeightRequest="38"
                                                    VerticalOptions="Center"
                                                    HorizontalOptions="FillAndExpand">
    
                                <custom:CustomDoneEntry.Behaviors>
                                    <b:EventHandlerBehavior EventName="TextChanged">
                                        <b:InvokeCommandAction Command="{Binding SearchCommand}" />
                                    </b:EventHandlerBehavior>
                                </custom:CustomDoneEntry.Behaviors>
    
                            </Entry>
    

    I use this library but also check out corcav behaviors

    https://www.nuget.org/packages/Behaviors.Forms/

    Can I add a behaviour without using a nuget package? how does package help? I am bit confused sorry

  • NMackayNMackay GBInsider, University mod
  • dinobdinob USUniversity ✭✭✭

    @NMackay said:
    @JenalynParagados

    I would recommend using behaviors if your writing a XAML MVVM app.

              <Entry x:Name="EntrySearchTerm"
                                                    Grid.Column="0"
                                                    Text="{Binding SearchTerm}"
                                                    Placeholder="Name (min 2 chars)"
                                                    MinimumHeightRequest="38"
                                                    VerticalOptions="Center"
                                                    HorizontalOptions="FillAndExpand">
    
                                <custom:CustomDoneEntry.Behaviors>
                                    <b:EventHandlerBehavior EventName="TextChanged">
                                        <b:InvokeCommandAction Command="{Binding SearchCommand}" />
                                    </b:EventHandlerBehavior>
                                </custom:CustomDoneEntry.Behaviors>
    
                            </Entry>
    

    I use this library but also check out corcav behaviors

    https://www.nuget.org/packages/Behaviors.Forms/

    Thanks for sharing this

  • Liêm_NguyễnLiêm_Nguyễn USMember ✭✭✭✭
    edited July 1

    @NMackay said:
    @JenalynParagados

    I would recommend using behaviors if your writing a XAML MVVM app.

              <Entry x:Name="EntrySearchTerm"
                                                    Grid.Column="0"
                                                    Text="{Binding SearchTerm}"
                                                    Placeholder="Name (min 2 chars)"
                                                    MinimumHeightRequest="38"
                                                    VerticalOptions="Center"
                                                    HorizontalOptions="FillAndExpand">
    
                                <custom:CustomDoneEntry.Behaviors>
                                    <b:EventHandlerBehavior EventName="TextChanged">
                                        <b:InvokeCommandAction Command="{Binding SearchCommand}" />
                                    </b:EventHandlerBehavior>
                                </custom:CustomDoneEntry.Behaviors>
    
                            </Entry>
    

    I use this library but also check out corcav behaviors

    https://www.nuget.org/packages/Behaviors.Forms/

    Could you please tell me some sample code to enable/disable a Button when Entry.Text nut null.
    Thank!

  • nike10nike10 Member ✭✭

    Could you please tell me some sample code to enable/disable a Button when Entry.Text nut null.

    @Liêm_Nguyễn Have a look at this https://www.davidbritch.com/2017/03/validating-user-input-in-xamarinforms-iv.html

Sign In or Register to comment.