0

I am working with Xamarin Forms and I have a Label in XAML. I wanted to make it so that when a user taps on the label an Entry is made visible with which they can enter new text for the Label. I've gotten it to work by looking up similar solutions but I don't quite understand how it works. Here is the specific line of code that I don't understand:

Title1Entry.Completed += (sender, e) => Title1Entry_Completed(sender, e);

What is the += operator doing?

XAML

                <Label x:Name="Term1Label"
                   Text="{Binding Title1}"
                   TextColor="White"
                   Margin="20,15,0,0"
                   FontSize="30"
                   FontAttributes="Bold">

                    <!--Tap on Title to change-->
                    <Label.GestureRecognizers>
                        <TapGestureRecognizer Command="{Binding Term1Label_Clicked}"/>
                    </Label.GestureRecognizers>
                </Label>
 
                <Entry x:Name="Title1Entry"
                    Text="{Binding Title1}"
                       TextColor="White"
                       FontSize="30"
                       FontAttributes="Bold"
                       Margin="20,15,0,0"
                       Grid.Column="0"
                       Grid.Row="0" IsVisible="False" IsTextPredictionEnabled="False" 
                                    InputTransparent="False" ReturnType="Done"
                       VerticalTextAlignment="Start"
                       HorizontalTextAlignment="Start"/>

C#

public Term1Page()
        {
            InitializeComponent();
            BindingContext = this;

            Title1Entry.Completed += (sender, e) => Title1Entry_Completed(sender, e); //This is the part I don't understand
        }

private void Title1Entry_Completed(object sender, EventArgs e)
        {
            Title1Entry.IsVisible = false;
            Term1Label.TextColor = Color.White;
        }
Chap
  • 61
  • 7

0 Answers0