WPF:ListView / Gridview中的复选框-如何在选中/未选中事件中获取ListItem? [英] WPF: Checkbox in a ListView/Gridview--How to Get ListItem in Checked/Unchecked Event?
本文介绍了WPF:ListView / Gridview中的复选框-如何在选中/未选中事件中获取ListItem?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在CheckBox_Checked和CheckBox_Unchecked事件背后的代码中,我希望能够访问复选框绑定到的MyList中的项目。
In the code behind's CheckBox_Checked and CheckBox_Unchecked events, I'd like to be able to access the item in MyList that the checkbox is bound to.
简单的方法吗?
<ListView ItemsSource="{Binding Path=MyList, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" MinHeight="100" MaxHeight="100">
<ListView.View>
<GridView>
<GridViewColumn>
<GridViewColumn.CellTemplate>
<DataTemplate>
<CheckBox Margin="-4,0,-4,0" IsChecked="{Binding MyBoolProperty}" Checked="CheckBox_Checked" Unchecked="CheckBox_Unchecked" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
推荐答案
CheckBox.DataContext
属性将保留绑定的项目。
The CheckBox.DataContext
property will hold the bound item.
这篇关于WPF:ListView / Gridview中的复选框-如何在选中/未选中事件中获取ListItem?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文