I turned the Horizontal ItemsControl into a Listbox so that I could select individual items, but found that the selection was broken. It took some time to separate the problematic bit.
Books = new[] { new Book{Id=1, Name="Book1"}, new Book{Id=2, Name="Book2"}, new Book{Id=3, Name="Book3"}, new Book{Id=4, Name="Book4"}, new Book{Id=3, Name="Book3"}, }; <DataTemplate DataType="{x:Type WPF_Sandbox:Book}"> <TextBlock Text="{Binding Name}"/> </DataTemplate> <ListBox ItemsSource="{Binding Books}"/>
If Book is a structure, selecting a list (default mode: one) goes wrong if you select an item with an equivalent structure in the list. e.g. Book3
If a book turns into a class (with semantics without meaning), the choice is fixed.
Choice (no one likes it yet):
- I chose structures because a small data structure and value type semantics are useful when comparing two instances for equality. Changing it in a class makes me lose the semantics of type values. I can no longer use the default values ββor redefine it for comparison by method.
- Add the differentiating attribute of the book, only to select a list for work (for example, an index).
- Eliminate duplicates. Impossible.
WPF list: selection problem : indicates that Listbox sets SelectedItem and when updating the user interface for this it just lights up all the items in the list that are Equal(SelectedItem) . Not sure why .. highlighting SelectedIndex would make this problem go away; maybe I'm missing something. ListBox selects many items even in SelectionMode = "Single" : shows the same problem when list items are strings (value type semantics)
source share