C# WPF Binding Get Reference To Source Row From Selected Item
Binding a ListView:
ItemsSource="{Binding Path=DF.DocFieldEnum1rows, Mode=OneWay}".
开发者_运维百科DF.DocFieldEnum1rows
is List<DocFieldEnum1row>
.
Item template binding:
<Button Content="{Binding Path=FieldEnum1Row.StrValue, Mode=OneWay}"
Click="Button_Click" />.
In the Button_Click
I get access to the Path=FieldEnum1Row.StrValue
value, but how can I get access to the source DocFieldEnum1row
?
The DataContext
of your Button
should be the instance of the row.
private void buttonClickHandler(object sender, EventArgs e)
{
Button b = (Button)sender;
var row = (YourRowType)b.DataContext;
}
精彩评论