在WPF中,如何确定控件所在的网格中的列/行? [英] In WPF, how can I determine what column/row in a grid a control is in?

查看:111
本文介绍了在WPF中,如何确定控件所在的网格中的列/行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在动态构建网格,并将按钮放在其中一列中。当我点击一个按钮时,我想知道它的哪一行是我的网格。我怎么能找到它?

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?

推荐答案

您说按钮的Click事件处理程序:

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...
}

这篇关于在WPF中,如何确定控件所在的网格中的列/行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆