In WPF, how can I determine what column/row in a grid a control is in?

后端 未结 1 1183
情书的邮戳
情书的邮戳 2021-01-05 15:17

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...
    }
    
    0 讨论(0)
提交回复
热议问题