0
votes

I have a gridView the data is coming from a datasource.

How can i add a button to a gridviewitem datatemplate and add a click event handler to the button?

3
Are you using a view model? - N_A
Why I downvoted this question: meta.stackexchange.com/a/149138/133242 - Matt Ball
@MattBall While I agree that the poster needs to include more information about what they've tried and what their situation is, this is actually a legitimately difficult question for someone new to XAML (hard to see that if you aren't familiar with XAML though). - N_A

3 Answers

0
votes

If you genuinely need to have a button in your ItemTemplate - the easiest way to add an event handler is to create a UserControl for use in the ItemTemplate, put the button in it and add the event handler inside of that UserControl.

2
votes

An alternative way is to not actually use a Button at all and simply setting IsItemClickEnabled to true and using the ItemClick event.

0
votes

The appropriate way to do this is to bind the command of your button to a command property on the DataContext of the item which is templated.