title: Add comboBox items from code behind. [WPF]
body: <p>I grabbed this code from <a href="https://msdn.microsoft.com/en-us/library/ms753382(v=VS.85).aspx" rel="noreferrer">MSDN</a>. What Im trying to do is similar, but use a list instead of three different strings. so say</p>
  
  <pre><code>List&lt;string&gt; strList = new List&lt;string&gt;();
  strList.Add("Created with C#");
  strList.Add("Item 2");
  strList.Add("Item 3");
  
    //MSDN CODE BELOW
      cbox = new ComboBox();
          cbox.Background = Brushes.LightBlue;
          cboxitem = new ComboBoxItem();
          cboxitem.Content = "Created with C#";
          cbox.Items.Add(cboxitem);
          cboxitem2 = new ComboBoxItem();
          cboxitem2.Content = "Item 2";
          cbox.Items.Add(cboxitem2);
          cboxitem3 = new ComboBoxItem();
          cboxitem3.Content = "Item 3";
          cbox.Items.Add(cboxitem3);
  
          cv2.Children.Add(cbox);
  </code></pre>
  
  <p>Tried to do cbox.Items.Add(strList); Also tried a forloop to loop through each element, but that doesn't work either. Any ideas how I can achieve this? </p>
  
  <p><a href="https://i.stack.imgur.com/XAO4Z.png" rel="noreferrer"><img src="https://i.stack.imgur.com/XAO4Z.png" alt="enter image description here"></a></p>
  
  <p>XAML: </p>
  
  <pre><code>          &lt;Grid x:Name="grid44" DataContext="{StaticResource tBLPERMITSViewSource}" HorizontalAlignment="Left" VerticalAlignment="Top" Width="409"&gt;
                              &lt;Grid.ColumnDefinitions&gt;
                                  &lt;ColumnDefinition Width="Auto"/&gt;
                                  &lt;ColumnDefinition Width="Auto"/&gt;
                              &lt;/Grid.ColumnDefinitions&gt;
                              &lt;Grid.RowDefinitions&gt;
                                  &lt;RowDefinition Height="Auto"/&gt;
                              &lt;/Grid.RowDefinitions&gt;
                              &lt;Label Content="SPR PACKET ASSIGMENT" Grid.Column="0" HorizontalAlignment="Left" Margin="3" Grid.Row="0" VerticalAlignment="Center" FontWeight="Bold"/&gt;
                              &lt;ComboBox x:Name="sPR_ASSIGNEDComboBox" Grid.Column="1" DisplayMemberPath="SPR_ASSIGNED" HorizontalAlignment="Left" Height="Auto" Text="{Binding SPR_ASSIGNED}" ItemsSource="{Binding Items}" Margin="3,5,-114.35,5" Grid.Row="0" VerticalAlignment="Center" Width="238.35" Background="White" IsReadOnly="True" IsEditable="True" &gt;
  
                              &lt;/ComboBox&gt;
                          &lt;/Grid&gt;
  </code></pre>