1
votes

I have a typical game grid - a UniformGrid consisting of Buttons. The buttons are each data-bound to individual "Cell" objects. Is there a way to access the button itself (and by extension, the particular object that the button is bound to) in the Button's click handler?

1
I think this is what you're asking for stackoverflow.com/questions/12413985/… - kenny

1 Answers

4
votes

If each button handles its own click event then you can use sender that is passed to event handler:

var button = sender as Button;

or if you have one Button.Click handler for all buttons on UniformGrid for example

var button = e.OriginalSource as Button;

and then getting DataContext is as easy as:

var context = button.DataContext;