title: Add items to ComboBox at runtime?
body: <p>I am trying to add items to a <code>ComboBox</code> (say <code>Name="labelComboBox"</code>) at runtime when I pressed an add button (say with <code>Name="add2labels" Click="add2labels_Click"</code>). But the <code>ComboBox</code> cannot show the values I newly added. What did I miss?</p>
  
  <p>The following is the event handler for the add button:</p>
  
  <pre><code>private List&lt;String&gt; labels = new List&lt;String&gt;();
  ... ...
  private void add2labels_Click(object sender, RoutedEventArgs e)
  {
      labels.Add("new value");
  
      labelComboBox.ItemsSource = labels;
  }
  </code></pre>
  
  <p>P.S. I am pretty sure the values were added to <code>List&lt;String&gt; labels</code> correctly (its count did increase each time).</p>
  
  <hr>
  
  <h2>Updated with workable solutions (3 ways) :</h2>
  
  <ol>
  <li><p>Use <code>ObservableCollection</code> (@AnatoliyNikolaev's answer).</p>
  
  <p>Change <code>List&lt;String&gt; labels</code> to <code>ObservableCollection&lt;String&gt; labels</code>. And only need to call <code>labelComboBox.ItemsSource = labels;</code> once in all.</p></li>
  <li><p>Use <code>Binding</code> (@HarshanaNarangoda's answer).</p>
  
  <p>Add <code>ItemsSource="{Binding Path=labels}"</code> to <code>ComboBox</code>'s properties.</p></li>
  <li><p>Use <code>Refresh()</code> (@EliranPe'er's anwer).</p>
  
  <p>Change the event handler to:</p>
  
  <pre><code>... ...
  labelComboBox.ItemsSource = labels;
  labelComboBox.Items.Refresh();      // new added
  </code></pre></li>
  </ol>