All you have to do is get the DataContext:
If you have a list with items:
MyList.ItemSource = new List<Item>();
And in XAML:
<ListView x:Name="MyList"> <ListView.ItemTemplate> <DataTemplate> <Stackpanel> <TextBox Text="{Binding Name}" /> <Button Content="Add sth" Click="AddClick" /> </Stackpanel> </DataTemplate> </ListView.ItemTemplate> </ListView>
And in CodeBehind to access the element by clicking on the button in the list:
private void AddClick(sender, args){ var senderButton= (Button) sender; var item = (Item) sender.DataContext;
The var element is what you are looking for
source share