title: C# MVVM Combobox
body: <p>In XAML I have a combobox defined as:</p>
  
  <pre><code>&lt;ComboBox x:Name="UsernameComboBox" 
            ItemsSource="{Binding Users}" 
            DisplayMemberPath="Username" 
            SelectedItem="{Binding Path=SelectedName, Mode=TwoWay}"/&gt;
  </code></pre>
  
  <p>Right now, it doesn't show any default selected item.</p>
  
  <p>I fill the combo box with a list:</p>
  
  <pre><code>public List&lt;User&gt; Users
  {
      get
      {
          return _userRepository.RetrieveUsers();
      }
  }
  
  public List&lt;User&gt; RetrieveUsers()
  {
      _users = (from Users in _db.Users select Users).ToList();
  
      return _users;
  }
  </code></pre>
  
  <p>The proper Users being the ItemSource for the combobox. then in the XAML I defined SelectedItem and bound it to a property called Selected name.</p>
  
  <p>In code this looks like:</p>
  
  <pre><code>    private User _selectedName;
      public User SelectedName
      {
          get
          {
              return _selectedName;
          }
          set 
          {
              if (_selectedName == value) return;
              _selectedName = value;
              OnPropertyChanged("SelectedName");
          }
      }
  </code></pre>
  
  <p>How can I get my combobox to show a selectedItem at startup?</p>