Reputation: 372
I have a ComboBox with the following XAML
<ComboBox Name="CompanyComboBox"
ItemsSource="{Binding Path=CompanyList, Mode=OneWay}"
SelectedItem="{Binding Path=CurrentCompany, Mode=TwoWay}"
DisplayMemberPath="Name" />
Problem:
The selected option on 'company' is persisted, but never gets displayed on load. What's missing or going wrong, or what have I forgotten to do?
I have tried the following suggestions, that have so far not solve the issue:
Upvotes: 2
Views: 1196
Reputation: 71
Can we take a look at the view model please? Until this information is not present, may give following suspections.
Upvotes: 0
Reputation: 18550
You can try this: after populating CompanyList in your ViewModel, set the CurrentCompany to the first company, or a dummy item that says , or depending on your context.
Upvotes: 0
Reputation: 131
Check that the instance assigned to CurrentCompany is the actual one contained in CompanyList and not a duplicate of it.
Upvotes: 1
Reputation: 132658
You need to overwrite the Company.Equals()
method to return true
if the object's data is the same.
By default, it only returns true
if the two company objects being compared share the same spot in memory, and I am guessing that your CurrentCompany
object does not point to an object in CompanyList
, so the SelectedItem
is being set to null
Upvotes: 3