tags:

views:

250

answers:

1

Hi I am having checkBox defined in DataTemplate which is defined in resource.Xaml file.I am using this DataTemplate in my user control. I am adding this dataTemplate dynamically to GridView. Now I want to fire checked event of checkBox. How will I attache the event? my Xaml is like this

<ListView>
    <ListView.View>
        <GridView></GridView>
    </ListView.View>
</ListView>
A: 

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.

Matt Hamilton
This check box is in DataTemplate which I have to attach it to one of the GridViewColumn dynamically. Also DataTemplate I am using is not in same file It is defined in Resource.Xaml file. so I am unable to use above statement.
jolly
It doesn't matter where the DataTemplate lives. If you have CheckBox.Checked="..." on a parent control your event handler will get called when the CheckBox is checked. Put it on the Window itself if you have to.
Matt Hamilton