Is there any way to use x:Name of the stacklayout in listview at code behind in xamarin.forms?
This link explain how access elements withn listview ListView creates only one instance of each View Controls. We cannot access View Controls inside ListView directly. can be accessed indirectly.
async void DisplayData(object Sender, EventArgs e)
{
// access buttonclickhandler
var buttonClickHandler = (Button)Sender;
// access Parent Layout for Button
StackLayout ParentStackLayout = (StackLayout)buttonClickHandler.Parent;
// access first Label "name"
Label nameLabel = (Label)ParentStackLayout.Children[0];
// access second Label "phone"
Label phoneLabel = (Label)ParentStackLayout.Children[1];
// access third Label "age"
Label ageLabel = (Label)ParentStackLayout.Children[2];
string name = nameLabel.Text;
string phone = phoneLabel.Text;
string age = ageLabel.Text;
await DisplayAlert("Person Details", "Name is : " + name + ".\n Phone Number is: " + phone + "\n Age is : " + age, "OK");
}
https://www.xamarinpaul.com/2018/11/how-to-access-view-controls-inside-Xamarin-forms-ListView.html