开发者

How to attach checked event to CheckBox in DataTemplate in wpf

开发者 https://www.devze.com 2022-12-14 05:35 出处:网络
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 dynami

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消