With the below binding in XAML, the selected item is not displayed in a combobox (specifically, the current type is not displayed for a site). We are using the caliburn micro framework and DevForce Ideablade. MySite is an Ideablade entity.
<ComboBox Grid.Column="3" Grid.Row="3"
ItemsSource="{Binding MySiteTypes}"
DisplayMemberPath="description"
SelectedItem="{Binding MySite.SiteType, Mode=TwoWay}"
SelectedValuePath="description"/>
Code in the ViewModel:
private BindableCollection<SiteType> _mySiteTypes;
public BindableCollection<SiteType> MySiteTypes
{
get { return _mySiteTypes; }
set { _mySiteTypes = value; NotifyOfPropertyChange(() => MySiteTypes); }
}
Once I set the site type with the combobox (the types are present in the dropdown), it correctly displays the type and changes the type in the database. What am I missing, why doesn't it want to display the existing type the first time?
Ok, I found the solution (Myles J was close):
The selected item is evaluated before the items from the itemsource were loaded causing the selected item not to be displayed. I needed to call NotifyOfPropertyChange for MySite AFTER the async query completed that populates MySiteTypes.