How to populate wpf combobox in xaml

You should bind the ItemsSource of the combo box to the property of the List<string>.


Like this?

<ComboBox > 

<ComboBoxItem Content="January"></ComboBoxItem> 

<ComboBoxItem Content="February"></ComboBoxItem> 

<ComboBoxItem Content="March"></ComboBoxItem> 

<ComboBoxItem Content="April"></ComboBoxItem> 

// .... and so on....

</ComboBox>

In namespace add declaration:

xmlns:sys="clr-namespace:System;assembly=mscorlib"

then add combobox where appropriate:

<ComboBox>
  <sys:String>January</sys:String>
  <sys:String>February</sys:String>
  <sys:String>March</sys:String>
                ...
  <sys:String>December</sys:String>
</ComboBox>

Tags:

Wpf

Combobox