title: WPF ComboBox bind itemssource to different datacontext in MVVM
body: <p>I have a user control that has its datacontext set to a view model called <strong>EmployeeList_VM</strong>.  I then have a ContentControl within that user-control that has its datacontect set to a public property (<strong><em>EmployeeSelection</em></strong>) of the view model.  The ContentControl's datacontext is the same as the selected item binding of a listbox within the same user control.</p>
  
  <p>I want to have a combobox (of an observblecollection called <strong>EmployeeStatus</strong>) within the ContentControl bind its selecteditem to a property of the <strong>EmployeeSelection</strong> datacontext of the ContentControl.  I want the itemssource of the combobox to bind to a public property <strong>EmployeeStatus</strong> of the "parent" viewmodel <strong>EmployeeList_VM</strong>.</p>
  
  <p>I can get a list of the employees status to appear wihtin the combobox.  I can not get it to bind to the idStatus property of the <strong>EmployeeSelection</strong>.</p>
  
  <p>Here is What I have so far (some code removed for readability):</p>
  
  <pre><code>&lt;UserControl x:Class="FTC.View.EmployeeListView"
              xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
              xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
              xmlns:local="clr-namespace:FTC_Application"
              xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
              xmlns:cmd="http://www.galasoft.ch/mvvmlight"
              mc:Ignorable="d" 
              DataContext="{Binding EmployeeList_VM, Source={StaticResource Locator}}"
              d:DesignHeight="900" d:DesignWidth="1000"&gt;
  
          &lt;Expander x:Name="DetailExpander" Grid.Column="2" Header="employee detail" Style="{DynamicResource ExpanderStyle_FTC}" IsExpanded="True" Padding="8,0,0,10" &gt;
              &lt;Grid&gt;
                  &lt;Grid.ColumnDefinitions&gt;
                      &lt;ColumnDefinition Width="Auto"/&gt;
                      &lt;ColumnDefinition Width="*"/&gt;
                  &lt;/Grid.ColumnDefinitions&gt;
                  &lt;StackPanel Orientation="Vertical" HorizontalAlignment="Left" &gt;
                      &lt;Button Content="" Style="{DynamicResource ButtonSave}" Command="{Binding SaveCommand}" ToolTip="Save Changes" Margin="0,0,10,10"/&gt;
                      &lt;Button Content="" Style="{DynamicResource ButtonUndo}" Command="{Binding UndoCommand}" ToolTip="Undo Changes" Margin="0,0,10,10"/&gt;
                  &lt;/StackPanel&gt;
                  &lt;ScrollViewer Grid.Column="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"&gt;
                      &lt;ContentControl DataContext="{Binding Path=EmployeeSelection, Mode=TwoWay}" &gt;
                              &lt;!-- FTC SETTINGS GRID CONTENT--&gt;
                              &lt;Grid Grid.ColumnSpan="6" Grid.Row="1"&gt;
                                  &lt;Grid.ColumnDefinitions&gt;
                                      &lt;ColumnDefinition Width="30"/&gt;
                                      &lt;ColumnDefinition Width="*"/&gt;
                                      &lt;ColumnDefinition Width="*"/&gt;
                                      &lt;ColumnDefinition Width="*"/&gt;
                                      &lt;ColumnDefinition Width="*"/&gt;
                                  &lt;/Grid.ColumnDefinitions&gt;
                                  &lt;Grid.RowDefinitions&gt;
                                      &lt;RowDefinition Height="Auto"/&gt;
                                      &lt;RowDefinition Height="Auto"/&gt;
                                      &lt;RowDefinition Height="Auto"/&gt;
                                  &lt;/Grid.RowDefinitions&gt;
  
                                  &lt;TextBlock x:Name="SettingsHeading" Text="FTC Settings" Style="{StaticResource FTC_DetailHeading}" Grid.ColumnSpan="5"/&gt;
  
                                  &lt;TextBlock Text="Status" Style="{StaticResource FTC_DetailLabelSub}" Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="1"/&gt;
                                  &lt;ComboBox Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="2"
                                            Margin="5,5,16,5" Height="37"
                                            ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}},Path=DataContext.EmployeeStatus}"
                                            SelectedItem="{Binding idStatus, Mode=TwoWay}"
                                            SelectedValuePath="idStatus"
                                            DisplayMemberPath="chrCode" FontSize="18"/&gt;
  
                             &lt;/Grid&gt;
                      &lt;/ContentControl&gt;
                  &lt;/ScrollViewer&gt;
              &lt;/Grid&gt;
          &lt;/Expander&gt;
  &lt;/UserControl&gt;
  </code></pre>
  
  <p>I even tried the following change (I named the ContentControl DetailControl) for the selected item of the combobox:</p>
  
  <pre><code>SelectedItem="{Binding ElementName=DetailControl, Path=DataContext.idStatus}"
  </code></pre>
  
  <p>Can someone please help me get the selected item binding hooked up properly.  The combobox displays all the right items, but they do not bind to the EmployeeSelection.idStatus.</p>
  
  <p>Thanks in advance.</p>