title: WPF Data Binding to a Combo Box
body: <p>I am new to WPF, C# and data binding. I am just trying to bind a simple combo box to an ObservedCollection. Here is the code:</p>
  
  <pre><code> public class Directory
  {
      private string _ikey;
      public string IKey
      {
          get
          {
              return _ikey;
          }
          set
          {
              _ikey = value;
          }
      }
      private string _ivalue;
      public string IValue
      {
          get
          {
              return _ivalue;
          }
          set
          {
              _ivalue = value;
          }
      }
  
  }
  /// &lt;summary&gt;
  /// Interaction logic for MainWindow.xaml
  /// &lt;/summary&gt;
  public partial class MainWindow : Window
  
  {
      public ObservableCollection&lt;Directory&gt; DirectoryList = new ObservableCollection&lt;Directory&gt;();
  
      public MainWindow()
      {
          InitializeComponent();
  
          DirectoryList = new ObservableCollection&lt;Directory&gt;();
          Directory _dirtemp = new Directory();
          _dirtemp.IKey = "1";
          _dirtemp.IValue = "Steve";
          DirectoryList.Add(_dirtemp);
  
          _dirtemp = new Directory();
          _dirtemp.IKey = "2";
          _dirtemp.IValue = "John";
          DirectoryList.Add(_dirtemp);
  
  
  
  
      }
  }
  </code></pre>
  
  <p>My xaml looks like this:</p>
  
  <pre><code>&lt;Window x:Class="DataBindCombo.MainWindow"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:local="clr-namespace:DataBindCombo"
      Title="MainWindow" Height="350" Width="525"&gt;
  &lt;Grid&gt;
      &lt;ComboBox Height="48" HorizontalAlignment="Left" Margin="70,104,0,0" Name="comboBox1" VerticalAlignment="Top" Width="310"
                ItemsSource="{Binding Path=DirectoryList}"
                DisplayMemberPath="IValue"
                SelectedValuePath="IKey"
                &gt;
  </code></pre>
  
  <p>It seems like it should be simple. I was able to put the binding in the code behind and it worked fine, but I would like to have it bind through xaml.</p>
  
  <p>Any ideas? TIA</p>