My DataGridComboBoxColumn does not show any data. It's empty.
I have no problem to fill a ComboBox, but DataGridComboBoxColumn doesn't work.
.NetFramework 4.6.1
Model:
public class Address
{
public string Firstname { get; set; }
public string Lastname { get; set; }
public string Country { get; set; }
}
ViewModel:
public class AddressViewModel
{
public AddressViewModel()
{
LoadAdresses();
LoadCountries();
}
public List<Address> AddressList { get; set; }
public List<string> CountryList { get; set; }
private void LoadAdresses()
{
AddressList = new List<Model.Address>();
AddressList.Add(new Model.Address(){ Firstname = "Peter", Lastname = "R.", Country = "A" });
AddressList.Add(new Model.Address(){ Firstname = "Tom", Lastname = "A.", Country = "A" });
AddressList.Add(new Model.Address(){ Firstname = "Sam", Lastname = "F.", Country = "A" });
}
private void LoadCountries()
{
CountryList = new List<string>();
CountryList.Add("A");
CountryList.Add("D");
CountryList.Add("CH");
CountryList.Add("GB");
CountryList.Add("F");
}
}
View:
<Window.DataContext>
<vm:AddressViewModel/>
</Window.DataContext>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<DataGrid x:Name="AddressDataGrid" Grid.Row="0" ItemsSource="{Binding AddressList}" AutoGenerateColumns="False" >
<DataGrid.Columns>
<DataGridTextColumn Header="Firstname" Binding="{Binding Firstname}" />
<DataGridTextColumn Header="Lastname" Binding="{Binding Lastname}" />
<DataGridComboBoxColumn Header="Country"
SelectedItemBinding="{Binding Country}"
ItemsSource="{Binding CountryList}"/>
</DataGrid.Columns>
</DataGrid>
<!--This ComboBox works-->
<ComboBox Grid.Row="1" ItemsSource="{Binding CountryList}"/>
</Grid>
What is the reason for this behaviour?
The other combo box works!