0

I have some input fields to enter details. At the mid of entering, I wish to erase all details before I save it if I click a button like "cancel". I used name reference (x:Name), the '.Text' property, and using Clicked property, but I am not able to erase all of the fields on the click. So I want to reload the same page on button click as it becomes refreshed, looks as new as it was before entering details. How can I do that?

xaml part: (firstNameTxtBox field gets cleared but lastNameTxtBox does't)

<Label HorizontalTextAlignment="Start" FontSize="14" FontFamily="Helvetica" Margin="10,0,0,0" >
                                    <Label.FormattedText>
                                        <FormattedString>
                                            <Span Text="Your first name " TextColor="#2D2926"/>
                                            <Span Text="*" TextColor="#AB2328"/>
                                        </FormattedString>
                                    </Label.FormattedText>
                                </Label>

                                <control:KFOLiteEntry x:Name="firstNameTxtBox"
                                              IsMandatory="true"
                                              IsEnabled="{Binding IsFirstNameEnabled, Mode=OneWay}"
                                              MaxLength="40"
                                              Text="{Binding FirstName, Mode=TwoWay}"
                                              HeightRequest="40"
                                              CornerRadius="2"
                                              BorderWidth="1"
                                              BackgroundColor="#FAFAFA"
                                              Margin="10,0,0,24"
                                              Placeholder="First name"/>

<Label HorizontalTextAlignment="Start" FontSize="14" FontFamily="Helvetica" Margin="30,0,0,0">
                                    <Label.FormattedText>
                                        <FormattedString>
                                            <Span Text="Your last name " TextColor="#2D2926"/>
                                            <Span Text="*" TextColor="#AB2328"/>
                                        </FormattedString>
                                    </Label.FormattedText>
                                </Label>

                                <control:LastNameSearchBar x:Name="lastNameSearchBar"
                                                   ItemsSource="{Binding PreAuthVisitorList, Mode=TwoWay}" />

                                <control:KFOLiteEntry x:Name="lastNametxtBox"
                                              IsMandatory="true"
                                              IsEnabled="{Binding IsLastNameEnabled, Mode=OneWay}"
                                              MaxLength="40"
                                              Text="{Binding LastName, Mode=TwoWay}"
                                              Placeholder="Last Name"
                                              HeightRequest="40"
                                              CornerRadius="2"
                                              Margin="30,0,0,24"
                                              BorderWidth="1"
                                              BackgroundColor="#FAFAFA"/>

Button Code:

<Button x:Name="btnCancelCheckIn"
        HorizontalOptions="StartAndExpand"
        WidthRequest="163"
        HeightRequest="40"
        CornerRadius="2"
        Text="Cancel"
        TextColor="White"
        Margin="0,68,0,10"
        BackgroundColor="#AB2328"
        Opacity=".3"
        IsEnabled="False"
        IsVisible="False"
        Clicked="OnCancelChcekInClicked"/>

xaml.cs button click function:

public void OnCancelChcekInClicked(object sender, EventArgs e)
        {
            acCompanies.Text = "";
            Visitingtxt.Text = "";
            firstNameTxtBox.Text = "";
            lastNametxtBox.Text = "";
            visitorCompanyTxtBox.Text = "";
        }
  • You mean `KFOLiteEntry` can't be cleared? Could you please post the code of `KFOLiteEntry` and the ViewModel of your page? – Jessie Zhang -MSFT Mar 11 '22 at 08:47
  • No, KFOLiteEntry for other fields gets cleared. But for this field, it doesn't. KFOLiteEntry is a control type. I can't post their code here, I am not allowed to(illegal) . – Saurav O'Lee Mar 11 '22 at 09:21
  • `KFOLiteEntry for other fields gets cleared. But for this field, it doesn't.` Sorry, I'm not sure what you mean . Which control is not cleared? – Jessie Zhang -MSFT Mar 11 '22 at 09:33
  • I have edited the XAML part in question. So firstNameTxtBox gets cleared but lastNameTxtBox doesn't. – Saurav O'Lee Mar 11 '22 at 10:04
  • if you are using data binding you shouldn't set the `Text` properties directly, that defeats the purpose of using binding. To clear the entries you should really reset the properties of the bound object. – Jason Mar 11 '22 at 11:52

0 Answers0