It's easier if you see the code but I'll give you the specific problem. My listbox is set to contain a grid format and each listboxitem has a ListBoxItem.PreviewMouseLeftButtonDown event. The problem is, the selected item is always set to the previous item.
Here is what happens in steps:
1. My image loads up
2. I click a button to generate a grid overlay of 32x32 cells over the image, each a listboxitem in a cell of that overlay
3. I click on a cell
4. OnSelected method fires (each listboxitem is tied to this handler through the ListBoxItem.PreviewMouseLeftButtonDown event)
5. The SelectedItem is null when I click on cell (0,0)
6. If I click on cell (0,1), the ListBoxItem.PreviewMouseLeftButtonDown event fires but now the SelectedItem is set to the object in the previous cell (0,0) instead of (0,1). Then, clicking on (0,0) will show the SelectedItem as being (0,1) and so on.
7. Repeat for any other cell.
View Complete Post