问题
I am building a grid dynamically and putting buttons in one of the columns. When I click a button, I want to know what row of my grid it's in. How can I find this?
回答1:
In the Click event handler for the button you say:
int row;
Button btn = sender as Button;
if (btn != null)
{
row = Grid.GetRow(btn); // And you have the row number...
}
else
{
// A nasty error occurred...
}
来源:https://stackoverflow.com/questions/363100/in-wpf-how-can-i-determine-what-column-row-in-a-grid-a-control-is-in