2009-09-18 29 views
2

以下面的窗口布局爲例: 定義了一個Grid元素。它有3排。每行有一個Button元素。我如何獲得它所屬Button的RowDefinition對象?謝謝。在WPF中,如何從屬於它的UIElement中獲取RowDefinition對象?

注意:通過調用Grid.GetRow(Button element),我得到該Button元素的Grid.Row屬性。我不需要那個 - 而是我需要實際的RowDefinition對象。

回答

4

像這樣:

int rowIndex = Grid.GetRow(myButton); 

RowDefinition rowDef = myGrid.RowDefinitions[rowIndex]; 

或者在同一行:

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

非常好,感謝卡羅。 – Boris 2009-09-18 16:42:47

相關問題