2011-07-20 69 views
0

綁定一個ListView:C#WPF綁定獲取參考到源代碼行從選定的項目

ItemsSource="{Binding Path=DF.DocFieldEnum1rows, Mode=OneWay}". 

DF.DocFieldEnum1rowsList<DocFieldEnum1row>

項目模板綁定:

<Button Content="{Binding Path=FieldEnum1Row.StrValue, Mode=OneWay}" 
    Click="Button_Click" />. 

Button_Click我得到訪問Path=FieldEnum1Row.StrValue價值,但我怎樣才能訪問源DocFieldEnum1row

回答

0

您的ButtonDataContext應該是該行的實例。

private void buttonClickHandler(object sender, EventArgs e) 
{ 
    Button b = (Button)sender; 

    var row = (YourRowType)b.DataContext; 
} 
+0

完美。謝謝你,謝謝你,謝謝你 – Paparazzi

相關問題