WPF 绑定LISTVIEW 子控件的事件
程序员文章站
2022-03-07 17:04:01
...
1.我们可以用数据模版实现添加按钮
<ListView x:Name="Liv">
<ListView.View>
<GridView>
<GridViewColumn Header="Index" DisplayMemberBinding="{Binding Path=Index}" />
<GridViewColumn Header="Name" DisplayMemberBinding="{Binding Path=Name}" />
<GridViewColumn Header="Info">
<GridViewColumn.CellTemplate>
<DataTemplate>
<Button Width="30" Content="..." Click="BtnInfo_Click" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
点击按钮时 通过按钮的 DataContent 获取绑定的对象
private void BtnInfo_Click(object sender, RoutedEventArgs e)
{
var btn = sender as Button;
var player = btn.DataContext as Player;
}
上一篇: wpf代码实现listview绑定数据
下一篇: 设计模式-单例模式(JAVA实现)