title: Is this the best way to build AutoSuggest into a WPF ComboBox?
body: <p>I have a Nationality ComboBox like the one below and want to make it so that the user can type letters to <strong>narrow</strong> in on the choices. I could solve this the way I started below by adding <strong>logic</strong> in the NationalityComboBox_KeyDown method.</p>
  
  <p><strong>Is this the best way to build AutoSuggest into a ComboBox or is there a built-in way to do the same thing?</strong></p>
  
  <p><strong>XAML:</strong></p>
  
  <pre><code>&lt;ComboBox x:Class="TestComboSuggest343.NationalityComboBox"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      Height="300" Width="300"&gt;
      &lt;ComboBox.ItemTemplate&gt;
          &lt;DataTemplate&gt;
              &lt;TextBlock Text="{Binding Value}"/&gt;
          &lt;/DataTemplate&gt;        
      &lt;/ComboBox.ItemTemplate&gt;
  &lt;/ComboBox&gt;
  </code></pre>
  
  <p><strong>Code-Behind:</strong></p>
  
  <pre><code>public partial class NationalityComboBox : ComboBox
  {
      public NationalityComboBox()
      {
          InitializeComponent();
  
          Items.Add(new KeyValuePair&lt;string, string&gt;(null, "Please choose..."));
          Items.Add(new KeyValuePair&lt;string, string&gt;(null, "American"));
          Items.Add(new KeyValuePair&lt;string, string&gt;(null, "Australian"));
          Items.Add(new KeyValuePair&lt;string, string&gt;(null, "Belgian"));
          Items.Add(new KeyValuePair&lt;string, string&gt;(null, "French"));
          Items.Add(new KeyValuePair&lt;string, string&gt;(null, "German"));
          Items.Add(new KeyValuePair&lt;string, string&gt;(null, "Georgian"));
          SelectedIndex = 0;
  
          KeyDown += new KeyEventHandler(NationalityComboBox_KeyDown);
  
      }
  
      void NationalityComboBox_KeyDown(object sender, KeyEventArgs e)
      {
          SelectedIndex = 4; // can create logic here to handle key presses, e.g. "G", "E", "O"....
      }
  }
  </code></pre>