在我的应用程序中,我有这个ComboBox:
<ComboBox x:Name="cmbNationality" SelectedValuePath="NationalityId"
SelectedValue="{Binding Path=NationalityId, ValidatesOnDataErrors=True, UpdateSourceTrigger=PropertyChanged, NotifyOnValidationError=True}"
Validation.Error="Validation_Error">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding NationalityAName}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
在某些模式下,我将其绑定到List<Nationality>
,在另一种模式下,我想将其ItemsSource设置为List<dynamic>
,其设置如下:
log.nationalities.Add(new { NationalityAName =
((TbNationality)cmbNationality.SelectedItem).NationalityAName });
但是当我将ItemsSource设置为此动态列表时,ComboBox呈现为空:
cmbNationality.ItemsSource = log.nationalities;
cmbNationality.SelectedIndex = 0;
修改
*请注意我不使用MVVM