lundi 17 avril 2017

How acced to checkbox into listbox

I'm trying make a listbox with checkboxes into it.

On xaml I have:

 <ListBox ItemsSource="{StaticResource ResourceKey=lstMaterialesCL}" SelectionMode="Multiple" Name="lstMaterial" >
     <ListBox.ItemTemplate>
         <DataTemplate>
             <CheckBox Name="chkMaterial" Content="{Binding DescCompuesta}"/>
         </DataTemplate>
     </ListBox.ItemTemplate>
 </ListBox>

and my ListBox looks as:

enter image description here

It is ok, but look it, when I checked "Municipales" the item in the ListBox is not selected, and when I select in the ListBox "Industriales" it is not checked

If I inspect the items selected into the ListBox it don't coincide with the items Checked

 foreach (var item in lstMaterial.SelectedItems)
 {
    MessageBox.Show(((MaterialesCL)item).DescCompuesta);
 }

It shows me "Oficiales", "Industriales" and "Destrucciones" but the user was want select "Municipales" and "Destrucciones" How I can to make coincide the ListBox items selected with the CheckBox checked if the CheckBox checked is mandatory?

I Hope explain me...can somebody help me?




Aucun commentaire:

Enregistrer un commentaire