Obtaining data from any UI element it is bound to
When a user who is working with your application performs a certain action, it's often essential to know on what object this action will be executed. For example, if a user clicks on a Delete button on an item, it's essential that you know which item is clicked so that you can write the correct code to delete that item. Also, when a user wants to edit an item in a list, it's necessary that you—the programmer—know which item in the list the user wants to edit.
In Silverlight, there is a very easy mechanism called
DataContext that helps us in this task. In this recipe, we're going to use the
DataContext to get the data when we need it.
If you want to follow along with this recipe, you ...