Reputation: 31
I have datagrid. Each row is element of OBservableCollection declared in cs file. Each DataGridRow has the extra column with Delete button and click event.
How do I get the corresponding element of my OBservableCollection in button click event function?
Upvotes: 2
Views: 417
Reputation: 3727
If you hook your button's click event, the sender should be button. The DataContext on that button should be the row item:
private void Button_Click(object sender, RoutedEventArgs e)
{
MyClass data = (sender as FrameworkElement).DataContext as MyClass;
}
Upvotes: 4