In WPF, how can I get the RowDefinition object from the UIElement that belongs to it?

和自甴很熟 提交于 2020-01-04 09:09:44

问题


Take the following window layout for example: There is a Grid element defined. It has 3 rows. Each row has one Button element. How do I get the RowDefinition object of the Button it belongs to? Thanks.

NOTE: By calling Grid.GetRow(Button element), I am getting the Grid.Row property of that Button element. I do not need that - instead I need the actual RowDefinition object.


回答1:


Like this:

int rowIndex = Grid.GetRow(myButton);

RowDefinition rowDef = myGrid.RowDefinitions[rowIndex];

Or in one line:

RowDefinition rowDef = myGrid.RowDefinitions[Grid.GetRow(myButton)];


来源:https://stackoverflow.com/questions/1445318/in-wpf-how-can-i-get-the-rowdefinition-object-from-the-uielement-that-belongs-t

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!