4

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.

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
Boris
  • 9,986
  • 34
  • 110
  • 147

1 Answers1

6

Like this:

int rowIndex = Grid.GetRow(myButton);

RowDefinition rowDef = myGrid.RowDefinitions[rowIndex];

Or in one line:

RowDefinition rowDef = myGrid.RowDefinitions[Grid.GetRow(myButton)];
Carlo
  • 25,602
  • 32
  • 128
  • 176