XAML:
<ComboBox x:Name="ComboBox" ItemsSource="{Binding myListofItems}" HorizontalAlignment="Left" Margin="256,41,0,-6" VerticalAlignment="Top" Width="108" Height="26" FontSize="13" />
C#:
public partial class MainWindow : Window, INotifyPropertyChanged
{
private List<string> _myListOfItems = new List<string> ();
public List<string> myListOfItems
{
get { return (_myListOfItems); }
set
{
_myListOfItems = value;
OnPropertyChanged ("myListOfItems");
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string propertyName)
{
var handler = PropertyChanged;
if (handler != null) {
handler (this, new PropertyChangedEventArgs (propertyName));
}
}
public MainWindow()
{
InitializeComponent ();
this.DataContext = this;
// Start Populating your List here
// Example:
for (int i = 0; i < 10; i++) {
myListOfItems.Add (i.ToString ());
}
}
}