Here is a simple XAML code.

<StackLayout> <Label x:Name="Label1"/> <Button Clicked="Button1_Clicked"/> </StackLayout> 

I want for example when you click on the button to change the text Label1 to Hello World

 private void Button1_Clicked(object sender, EventArgs e) { Label1.Text = "Hello World!"; } 

But when I turn to Label1, it says to me that there is no such variable.

Help fix

  • If StackLayout is located in DataTemplate, no way. Use the mvvm pattern. - Emigrant
  • StackLayout is only in ContentPage - SHULER at 6:49 pm
  • I have the MainPage.xaml file (it contains all the xaml code), and MainPage.xaml.cs is in it, the method is in MainPage.xaml.cs - SHULER

1 answer 1

I have already solved the problem, it turns out it was necessary to simply save the XAML code