I have a ComboBox like this
I used x:Bind for the ItemResource and added ViewModel inside code behind, and solved this problem.
You ComboBox
isn't blank, but it don't know how to render your MaxXXAgeMembers
. You should use ItemTemplate
to tell this to him. For Ex:
<ComboBox
Grid.Column="1"
Padding="5,0,0,0"
SelectedValue="{Binding MaxXXAge, Mode=TwoWay, Converter={StaticResource MaxXXAgeToMaxXXAgeMemberConverter}}"
ItemsSource="{Binding ElementName=SettingsXXScrollViewer, Path=DataContext.MaxXXAgeMemberGroup, Mode=OneWay}">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Description}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
It's blank because you don't have anything selected in the first place. If I'm not mistaken, you have to either use SelectedItem
to bind your selection or SelectedValue
with SelectedValuePath
.
I actually never use SelectedValue
with SelectedValuePath
myself, so after initializing collection of items which ComboBox.ItemSource will be binded to - for example ObservableCollection<Person> Persons {get; set;}
- I also set selected item property Person SelectedPerson {get; set;}
to one of the values from collection. Then I bind ComboBox.SelectedItem to this property, so on initialization it shows predefined selected value.
I guess you can achieve the same with SelectedValue
and SelectedValuePath
, but you have to use them together as described here.