iv’e got a ListBox which is bound to a list of Player , the listbox’s parent
as a datacontext with a property of Players .
<ListBox>
<ListBox.Items>
<Binding Path="Players"></Binding>
</ListBox.Items>
<DataTemplate>
<ListBoxItem>
<TextBlock Text="{Binding Name}"></TextBlock>
<Button ToolTip="Invite To Play" x:Name="btn_InviteToPlay" Click="btn_InviteToPlay_Click>
</ListBoxItem>
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox>
on the buttons click event i need to get the value of Player that is bound to this
listboxitem (the one containing the button which was clicked )
private void btn_InviteToPlay_Click(object sender, RoutedEventArgs e)
{
Button btn = (Button)sender;
// how to retrieve player bound to current listboxitem ?
}
btn.DataContextshould already contain thePlayeras theDataContextis inherited by controls in theListBoxItem.