This is an old revision of the document!
DataTemplate
<DataTemplate x:Key="postBody" TargetType="{x:Type Post}"> <Grid> <TextBlock Text="{Binding Path=author}"/> <Button Click="btnDelete_Click" Content="Delete"/> </Grid> </DataTemplate> <ListBox ItemTemplate="{StaticResource postBody}" ItemSource="{Binding Posts}"/>
Code behind to get a reference to object owning btnDelete:
private void btnDelete_Click(object sender, RoutedEventArgs e) { var post = ((Button)sender).DataContext as Post; if (post == null) { throw new InvalidOperationException("Invalid DataContext"); } Console.WriteLine(post.author); }