relief
relief

Reputation: 31

WPF. Get clicked row item values

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

Answers (1)

JacobJ
JacobJ

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

Related Questions