简体   繁体   English

如何在Windows Phone中的ListBox中获取“CheckBox.Checked”项

[英]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. 如何获取CheckBox.Checked项目,我的复选框位于listBox内,listbox与类绑定。 My class has two items: Name and Id 我的课有两个项目: NameId

My code below: 我的代码如下:

I want that when I check on checkbox, in the background, I want Id of checked item. 我希望当我选中复选框时,在后台,我想要检查项目的ID。

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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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