title: Getting SelectedItem of ComboBox (MVVM)
body: <p>I'd like to get the selected Item of a ComboBox using the MVVM Pattern (beginner).
  I've read that this could be achieved by binding the SelectedItem Property to a Property in the ViewModel.</p>
  
  <p>XAML:</p>
  
  <pre><code>&lt;ComboBox ItemsSource="{Binding RoomLockerLinkCollection}" 
          DisplayMemberPath="Room.Name" 
          SelectedItem="{Binding SelectedRoom}"/&gt;
  </code></pre>
  
  <p>ViewModel:</p>
  
  <pre><code>public Room SelectedRoom { get; set; }
  </code></pre>
  
  <p>But it's not working - the only thing thats happening is a appearing red border around that ComboBox - in addition after selecting a new item in the ComboBox the "SelectedRoom" property in my VM is still null.</p>
  
  <p>Edit 1 : </p>
  
  <p>One short additional question:</p>
  
  <p>The binding works fine - at least for the top "category". My Wrapper-Class also contains a list of lockers.</p>
  
  <pre><code>&lt;ComboBox DataContext="{Binding SelectedItem, ElementName=_cmbRoomSelection}" ItemsSource="  {Binding LockerCollection}" DisplayMemberPath="Name" SelectedValue="{Binding SAVM.SelectedLocker, Mode=TwoWay}" /&gt;
  </code></pre>
  
  <p>When I check the type of the SelectedValue it's a "Locker" - fine.
  But the SelectedLocker-Property in my VM stays null...</p>
  
  <p>Additional, could s.o. explain when to use "SelectedItem" and "SelectedValue"? What's the difference? Setting the DataContext in the xaml code above can not be done by binding the SelectedValue...</p>
  
  <p>Edit 2 (Solution) : </p>
  
  <p>Okay, got it!</p>
  
  <p>As I figured out I've reset my DataContext - now the Property SAVM of course could not be found.</p>
  
  <p>Solution:</p>
  
  <pre><code>&lt;ComboBox DataContext="{Binding SelectedItem, ElementName=_cmbRoomSelection}" 
  ItemsSource="{Binding LockerCollection}" 
  DisplayMemberPath="Name" 
  SelectedValue="{Binding SAVM.SelectedLocker **ElementName=_vStorage**, Mode=TwoWay}" /&gt;
  </code></pre>