Wow. That's a weird issue. Even weirder dropping the code into my own project and verifying the problem!
From the random nature of the checkboxes, and the fact that when you scroll down some will be checked, and when you scroll back others will be checked, I'd say it'd have something to do with the checkboxes being created and destroyed when they are pushed on and off the screen by the scrolling motion. The Listbox only generates the ItemTemplates for the items currently on the screen (and a small buffer).
What I'd be doing instead, and what's worked for me in the past, is to create a data structure that combines the boolean 'checked' value with the integer.
So the steps are as follows:
- Make a class that has an int and a bool as two properties.
- Modify your datatemplate so that it binds the checkbox to the bool and the label to the int, as follows:
<datatemplate>
<stackpanel orientation="Horizontal">
<checkbox ischecked="{Binding theBool, Mode=TwoWay}" />
<textblock text="{Binding theInt}" />
</stackpanel>
</datatemplate>
Then to check if an item is checked or not, you can simply iterate through lstCheckbox.Items and check each object for "obj.theBool == true".
That's the best solution I can think of, hope it helps!