Problems Using ListBox and Observable Collection as Debug Log

I have a list attached to an observable collection of a view model:

This works fine, minus one small hitch ... assuming the observable collection contains strings, it all breaks when elements of the collection with the same values โ€‹โ€‹are added to the collection, what's the best way to handle this? Custom structure instead of strings and then datatemplate?

edit: completely forgot to explain the behavior ... he selects several values, when I click on one record, all other values โ€‹โ€‹with the same text are selected.

+3
source share
1 answer

- , Selector. ObservableCollection, , , . /struct .

public class Info
{
    public string Name { get; set; }
}

// ..

MyList = new ObservableCollection<Info>(new List<Info> { new Info { Name = "Hello World" }, new Info { Name = "Hello World" }, new Info { Name = "Hello World" } });

.

<ListBox ItemsSource="{Binding MyList}" DisplayMemberPath="Name" />
+3

Source: https://habr.com/ru/post/1720920/


All Articles