简体   繁体   中英

How to get “CheckBox.Checked” item inside ListBox in Windows Phone

How do I get CheckBox.Checked item, my checkbox is inside listBox and listbox is binded with a class. My class has two items: Name and Id

My code below:

I want that when I check on checkbox, in the background, I want Id of checked item.

private void CheckBox1_Checked(object sender, RoutedEventArgs e)
{
    ListBoxItem checedItem = this.listBox1.ItemContainerGenerator.ContainerFromItem((sender as CheckBox).DataContext) as ListBoxItem;

    if (checedItem != null)
    {
        checedItem.IsSelected = true;
    }
}

May this help you.

private void CheckBox1_Checked(object sender, RoutedEventArgs e)
{
    var checkBox = (CheckBox)sender;\
    var data = (Your class)checkBox.DataContext;
    var id = data.id;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM