title: How can I set selected value of a XAML Combobox?
body: <p><strong>Why in the following example is the combobox set to blank instead of "Mr."?</strong></p>
  
  <p><strong>XAML:</strong></p>
  
  <pre><code>&lt;Window x:Class="TestComb82822.Window1"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      Title="Window1" Height="300" Width="300"&gt;
      &lt;StackPanel HorizontalAlignment="Left"&gt;
          &lt;ComboBox SelectedValue="{Binding Salutation}" Width="200"&gt;
              &lt;ComboBoxItem&gt;Company&lt;/ComboBoxItem&gt;
              &lt;ComboBoxItem&gt;Ms.&lt;/ComboBoxItem&gt;
              &lt;ComboBoxItem&gt;Mr.&lt;/ComboBoxItem&gt;
          &lt;/ComboBox&gt;
      &lt;/StackPanel&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p><strong>Code behind:</strong></p>
  
  <pre><code>using System.Windows;
  using System.ComponentModel;
  
  namespace TestComb82822
  {
      public partial class Window1 : Window, INotifyPropertyChanged
      {
          #region ViewModelProperty: Salutation
          private string _salutation;
          public string Salutation
          {
              get
              {
                  return _salutation;
              }
  
              set
              {
                  _salutation = value;
                  OnPropertyChanged("Salutation");
              }
          }
          #endregion
  
          public Window1()
          {
              InitializeComponent();
              DataContext = this;
              Salutation = "Mr.";
          }
  
          #region INotifiedProperty Block
          public event PropertyChangedEventHandler PropertyChanged;
  
          protected void OnPropertyChanged(string propertyName)
          {
              PropertyChangedEventHandler handler = PropertyChanged;
  
              if (handler != null)
              {
                  handler(this, new PropertyChangedEventArgs(propertyName));
              }
          }
          #endregion
  
      }
  }
  </code></pre>
  
  <h1>Second try:</h1>
  
  <p>Bryan, SelectedItem and WindowLoaded doesn't work either, this still makes the ComboBox blank:</p>
  
  <p><strong>XAML:</strong></p>
  
  <pre><code>&lt;Window x:Class="TestCombo234.Window1"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      Title="Window1" Height="300" Width="300"&gt;
      &lt;StackPanel HorizontalAlignment="Left"&gt;
          &lt;ComboBox SelectedItem="{Binding Salutation}" Width="200"&gt;
              &lt;ComboBoxItem&gt;Company&lt;/ComboBoxItem&gt;
              &lt;ComboBoxItem&gt;Ms.&lt;/ComboBoxItem&gt;
              &lt;ComboBoxItem&gt;Mr.&lt;/ComboBoxItem&gt;
          &lt;/ComboBox&gt;
      &lt;/StackPanel&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p><strong>Code Behind:</strong></p>
  
  <pre><code>using System.Windows;
  using System.ComponentModel;
  
  namespace TestCombo234
  {
      public partial class Window1 : Window, INotifyPropertyChanged
      {
          #region ViewModelProperty: Salutation
          private string _salutation;
          public string Salutation
          {
              get
              {
                  return _salutation;
              }
  
              set
              {
                  _salutation = value;
                  OnPropertyChanged("Salutation");
              }
          }
          #endregion
  
          public Window1()
          {
              InitializeComponent();
              DataContext = this;
              Loaded += new RoutedEventHandler(Window1_Loaded);
          }
  
          void Window1_Loaded(object sender, RoutedEventArgs e)
          {
              Salutation = "Mr.";
          }
  
          #region INotifiedProperty Block
          public event PropertyChangedEventHandler PropertyChanged;
  
          protected void OnPropertyChanged(string propertyName)
          {
              PropertyChangedEventHandler handler = PropertyChanged;
  
              if (handler != null)
              {
                  handler(this, new PropertyChangedEventArgs(propertyName));
              }
          }
          #endregion
      }
  }
  </code></pre>