【发布时间】:2012-02-20 16:19:16
【问题描述】:
iv'e 有一个 ListBox 绑定到列表框的父 Player 列表 作为具有 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>
在按钮单击事件上,我需要获取绑定到此的 Player 的值 listboxitem(包含被点击按钮的那个)
private void btn_InviteToPlay_Click(object sender, RoutedEventArgs e)
{
Button btn = (Button)sender;
// how to retrieve player bound to current listboxitem ?
}
【问题讨论】:
标签: c# wpf xaml data-binding