How to attach checked event to CheckBox in DataTemplate in wpf
Hi I am having a CheckBox
de开发者_StackOverflow社区fined in a DataTemplate
which is defined in resource.Xaml file. I am using this DataTemplate
in my user control. I am adding this DataTemplate
dynamically to a GridView
. Now I want to fire the checked event of a CheckBox
. How will I attach the event? My Xaml is like this:
<ListView>
<ListView.View>
<GridView></GridView>
</ListView.View>
</ListView>
Use the fact that the CheckBox.Checked event bubbles up to its parent controls:
<ListView CheckBox.Checked="YourCheckedEventHandler">
...
</ListView>
Obviously you'll have to check the item whose CheckBox was checked in the event handler. The easiest way to do that is to look at the DataContext of the sender parameter, or possibly the Source property on the "e" parameter.
精彩评论