title: WPF binding navigation property to combobox
body: <p>Context: I am using EF 5 and trying to bind two entities to a WPF form. It works fine with simples property-to-textbox binding, but I'd like to bind a navigation property object to a combobox. I am learning WPF so this may be obvious.</p>
  
  <p>I have two EF entities:</p>
  
  <pre><code>Product { int Id, string Name, Category Category }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>Category { int Id, string Description }
  </code></pre>
  
  <p>I made a WPF form to create and edit products, it is something like this (simplified):</p>
  
  <pre><code>        &lt;Window.Resources&gt;
              &lt;CollectionViewSource x:Key="productViewSource" d:DesignSource="{d:DesignInstance my:product, CreateList=True}" /&gt;
              &lt;CollectionViewSource x:Key="categoryViewSource" d:DesignSource="{d:DesignInstance my:category, CreateList=True}" /&gt;
          &lt;/Window.Resources&gt;
          &lt;Grid DataContext="{StaticResource productViewSource}"&gt;
              &lt;Label Content="Id" Height="28" HorizontalAlignment="Left" Margin="6,6,0,0" Name="label1" VerticalAlignment="Top" /&gt;
              &lt;TextBox Height="23" HorizontalAlignment="Left" Margin="61,8,0,0" Name="txtId" Text="{Binding Path=Id, Mode=TwoWay, ValidatesOnExceptions=true, NotifyOnValidationError=true}" VerticalAlignment="Top" Width="56" IsEnabled="False" /&gt;
              &lt;Label Content="Name" Height="28" HorizontalAlignment="Left" Margin="6,38,0,0" Name="label2" VerticalAlignment="Top" /&gt;
              &lt;TextBox Text="{Binding Path=Name, Mode=TwoWay, ValidatesOnExceptions=true, NotifyOnValidationError=true}" Height="23" HorizontalAlignment="Left" Margin="61,40,0,0" Name="txtNome" VerticalAlignment="Top" Width="183" IsEnabled="False" /&gt;
  
              &lt;Label Content="Category" Height="28" HorizontalAlignment="Left" Margin="6,129,0,0" Name="label5" VerticalAlignment="Top" /&gt;
              &lt;ComboBox Height="23" HorizontalAlignment="Left" Margin="72,132,0,0" Name="comboCategory" VerticalAlignment="Top" Width="172" 
                        DisplayMemberPath="Description" 
                        SelectedValuePath="Id" 
                        SelectedValue="{Binding Path=Category, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                        ItemsSource="{Binding Path=categoryViewSource, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}"&gt;
              &lt;/ComboBox&gt;
           &lt;/Grid&gt;
  </code></pre>
  
  <p>The code to load the two View Sources is this:</p>
  
  <pre><code>private void Window_Loaded(object sender, RoutedEventArgs e)
      {
          context = new DBEntities();
  
          var productViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("productViewSource")));
          context.Product.Include(p =&gt; p.Category);
          context.Product.Load();
          ProductViewSource.Source = context.Product.Local;
  
          var categoryViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("categoryViewSource")));
          categoryViewSource.Source = context.Category.ToList();
      }
  </code></pre>
  
  <p>When the window loads the two textboxes work, but the combobox is always empty.</p>
  
  <p>Probally this is what is wrong, but I can't seem to find a way to make it work.</p>
  
  <pre><code>ItemsSource="{Binding Path=categoryViewSource, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}"
  </code></pre>