开发者

C# WPF Binding Get Reference To Source Row From Selected Item

开发者 https://www.devze.com 2023-03-22 01:17 出处:网络
Binding a ListView: ItemsSource=\"{Binding Path=DF.DocFieldEnum1rows, Mode=OneWay}\". 开发者_运维百科DF.DocFieldEnum1rows is List<DocFieldEnum1row>.

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;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消