WPF ComboBox: Invalid item displayed

This is the initial situation:

XAML:

<ComboBox Grid.Row="0" Grid.Column="1" Margin="0,3" HorizontalAlignment="Stretch" DisplayMemberPath="DisplayText" ItemsSource="{Binding ObjectSource}" /> 

ViewModel:

 public Collection<MyObjects> ObjectSource { get { return this.objectSource; } set { this.SetProperty(ref this.objectSource, value); } } 

My objects contain a name (string), valid from (dateTime) and displayText (only a string) that combine the name and the valid for display.

In this simple situation, I can open combobox and see all the records, after selecting one of them, the correct displayed text inside the combobox will also be displayed. Now I re-open the dropdown menu area and select another entry. As a result, the selected item is switched (since you can see the item with a high value when you open the drop-down entry again). But the display item inside the combobox has not changed, there is still a DisplayText for the first choice.

Screenshot of the result situation

Does anyone have an idea for me why combobox is not updating? thanks in advance

Edit: Thank you all for your help. The problem was the mistake of redefining peers.

+6
source share
1 answer

just for completeness :)

you need to check the override of Equals () and make sure this is not an error. I had the same issue with the list these days.

+1
source

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


All Articles