How do I filter out duplicate entries in my list when bound to a data source?
The fact that you have duplicate entries probably suggests that you are binding to the wrong data source. But, in any case, there are possibly valid scenarios where this is necessary. Here is a solution.
One way is to group the list by name using CollectionViewSource and then bind the Groups to the ListBox. Here is some code:
(for better code formatting, look at this thread: Distinct Value Filter For ListBox
If you Contracts collection is like this:
Then you can use the CollectionViewSource to bind to it and group the colelction by Name as follows:
This will render the listbox the way you want - ignoring the duplicate names. You can then interpret the selected item as follows: