c# - WPF DataGrid - Button in a column, getting the row from which it came on the Click event handler -


I have set items of my WPF degrid in my list of returned objects from DAL. I've also added an extra column that has a button, xaml is below.

  & amp; Toolkit: DataGridTemplateColumn MinWidth = "100" Header = "View" & gt; & Lt; Toolkit: DataGridTemplateColumn.CellTemplate & gt; & Lt; DataTemplate & gt; & Lt; Button click = "Button_Click" & gt; View Details & lt; / Button & gt; & Lt; / DataTemplate & gt; & Lt; / Toolkit: DataGridTemplateColumn.CellTemplate & gt; & Lt; / Toolkit: DataGridTemplateColumn & gt;  

This presents well, however, on the Button_Click method, is there any way that I can get a line on the datagram where the button remains? More specifically, one of the attributes of my object is "Id", and I want to be able to pass it in another form constructor in event handler.

  Private Zero Button_Click (Object Sender, RoutedEventArgs E) {// I would like to know which button "I" can retrieve the "id"}  < / Pre> 

Maybe I need extra in my XML, or maybe I'm going in the way of an intersection in this regard? Any help / advice appreciated.

Actually your button line will obtain the datacontext of the data object. I'm calling it as MyObject and hope MyObject.ID is the one you want.

  Private Zero Button Button (Object Sender, Routing Event E) {MyObject obj = (Framework Element) Sender). DataContext as MyObject; // MyObject.ID},  

Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -