开发者

WPF. Get clicked row item values

开发者 https://www.devze.com 2023-03-21 17:00 出处:网络
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.

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 cl开发者_如何学Goick event function?


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;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消