I have a VB.net WPF application that creates a list from a databind. For each row in the databind, it generates a textblock that displays the information from different fields in the databind. It also generates a button which I would like to run a subroutine when clicked.
When I click the button, I want it to be able to get the information from the databind on the column the button is clicked, and to pass it to the subroutine so the code-behind can use that information.
Any ideas?
This sounds like a job for a Routed Command. Pass your data object as the command parameter, and set up a command binding to handle when the command is invoked. So, in your data template, you’d have something like:
Then, in the handler for the command (set up through a CommandBinding) you’ll have the command parameter passed to you in the Parameter property of the ExecutedRoutedEventArgs. Read the article that I linked to.