title: How to bind custom object data to a ComboBox
body: <p>I have a custom class <code>Contact</code>.</p>
  
  <p>I am trying to bind a <code>List&lt;Contact&gt;</code> to a ComboBox.</p>
  
  <p>But I can't get the right syntax/commands for the <code>Windows.Resources</code> part, e.g. the code below gives the error "The type reference cannot find a public type named 'List'", what do I need to fix in <code>Windows.Resources</code> to get this to work?</p>
  
  <p><strong>XAML:</strong></p>
  
  <pre><code>&lt;Window x:Class="dpwpf.Window1"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      Title="Window1" Height="300" Width="300"
      xmlns:system="clr-namespace:System;assembly=mscorlib"
      xmlns:local="clr-namespace:dpwpf"&gt;
  
      &lt;Window.Resources&gt;
          &lt;ObjectDataProvider
              x:Key="contacts"
              MethodName="GetContacts"
              ObjectType="{x:Type system:List}"&gt;
              &lt;ObjectDataProvider.MethodParameters&gt;
                  &lt;x:Type TypeName="local:GetContacts"/&gt;
              &lt;/ObjectDataProvider.MethodParameters&gt;
          &lt;/ObjectDataProvider&gt;
      &lt;/Window.Resources&gt;
  
  
      &lt;StackPanel&gt;
          &lt;StackPanel&gt;
              &lt;TextBlock Text="Select the contact:"/&gt;
              &lt;ComboBox ItemsSource="{Binding
                  Source={StaticResource contacts}}"/&gt;
          &lt;/StackPanel&gt;
      &lt;/StackPanel&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p><strong>Code behind class:</strong></p>
  
  <pre><code>namespace dpwpf
  {
      class StoreDB
      {
          private string connectionString = "App_Data/main.sqlite";
  
          public List&lt;Contact&gt; GetContacts()
          {
              SQLiteConnection conn = new SQLiteConnection("Data Source=" + connectionString);
              SQLiteCommand cmd = conn.CreateCommand();
  
              List&lt;Contact&gt; contacts = new List&lt;Contact&gt;();
              try
              {
                  conn.Open();
                  cmd.CommandText = String.Format("SELECT * FROM contacts");
                  SQLiteDataReader reader = cmd.ExecuteReader();
                  while (reader.Read())
                  {
                      Contact contact = new Contact(
                          Int32.Parse(reader[0].ToString()),
                          reader[1].ToString(),
                          reader[2].ToString()
                      );
                      contacts.Add(contact);
                  }
              }
              finally
              {
                  conn.Close();
              }
  
              return contacts;
          }
      }
  }
  </code></pre>