Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 359
Boris Avatar asked Oct 24 '25 02:10

Boris


1 Answers

Like this:

int rowIndex = Grid.GetRow(myButton);

RowDefinition rowDef = myGrid.RowDefinitions[rowIndex];

Or in one line:

RowDefinition rowDef = myGrid.RowDefinitions[Grid.GetRow(myButton)];
like image 90
Carlo Avatar answered Oct 27 '25 04:10

Carlo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!