I'm having a rather strange problem while working with a ListBox
on a WPF
program.
I've defined my ListBox
SelectionMode
as Single
, but it appear that even if visually I cannot select multiples items, it happens in the code.
As can be seen here :
When trying to do a workaround, I tried to use the function UnselectAll, it rather strangly still leave an item selected :
And as a last gift, once multiple items have been selected, if I try to click on my unselected visualy, selected in the code, item my application crash with a System.ArgumentException (I suppose it tries to select my item, that's already selected in fact, so it crashes because of adding a perfect duplicate ?)
I looked into ListBox is selecting many items even in SelectionMode="Single" that had kindof the same problem, but in my case I cannot visually select multiples items, and my items are completly distinct so it doesn't really help.
I don't have any custom behavior on ListBox.Click that could mess with something ...
my ListBox.ItemsSource
is bound to a list of Items.
I will decrement the value of a property of the selected Item when calling useItem
on it, but it is still the same item (I don't recreate it/remove it then add it again)
Where is my problem coming from ? How can I fix it ?