WPF listbox : problem with selection

Posted by KiTe on Stack Overflow See other posts from Stack Overflow or by KiTe
Published on 2009-10-22T13:10:01Z Indexed on 2010/05/27 0:21 UTC
Read the original article Hit count: 584

Filed under:
|
|

Hello.

In my XAML file, I have a ListBox declared like this :

           <ListBox x:Name="lstDeck" Height="280" ItemsSource="{Binding Path=Deck}"  >
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <ListBoxItem  Content="{Binding}" />
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>

In my view model, Deck is an ObservableCollection, so that binding directly displays the content of my collection.

But when I have several value that hold the same value (for example "10" six times), the selection in the ListBox has a weird behaviour : it select 2-3 elements instead of the only the one on which I clicked.

Moreover, when I click to another listBoxItem, it doesn't unfocus the previous selected one.

Then it is impossible to see which item is actually selected, and impossible to get the SelectedIndex value.

Has someone an idea?

© Stack Overflow or respective owner

Related posts about wpf

Related posts about listbox