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

查看:17
本文介绍了在 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天全站免登陆