title: WPF Combobox binding and SelectedValue with SelectedValuePath
body: <p>I am really struggling with data binding and the MVVM Methodology, though I like the concept I am just struggling.  I have created a WPF for that has multiple comboboxes and a button.  The first combobox will list database instance names.  the remaining comboboxes will be populated after the button is clicked.  Since I am having issues with the first, database instances, combobox I will only show my code for that.  When the application starts up the combobox is loaded and the first item is selected, as expected. The issue is when I select a new name my method that I expect to get called does not.  Can someone help me to understand why my method <code>public DBInstance SelectedDBInstance</code> is not getting executed when I have this in my XAML, <code>SelectedValue="{Binding SelectedDBInstance, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}</code>?</p>
  
  <p>Here is my XAML for the database instances combobox.  One question I have here is the "value" fpr SelectedValuePath, if I change it to say "DBInstanceName" it does not work.</p>
  
  <pre><code> &lt;ComboBox x:Name="cbxRLFDBInstances" ItemsSource="{Binding DBInstances}" 
                    SelectedValue="{Binding SelectedDBInstance, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
                    SelectedValuePath="value" DisplayMemberPath="DBInstanceName"/&gt;
  </code></pre>
  
  <p>Here is my ViewModel Code:</p>
  
  <pre><code>namespace DatabaseTest.ViewModel
  {
  
  class RLFDatabaseTableViewModel : INotifyPropertyChanged
  {
      Utilities dbtUtilities = new Utilities();
  
  
      public RelayCommand LoadDBInfoCommand
      {
          get;
          set;
      }
  
  
      public RLFDatabaseTableViewModel()
      {
          LoadDBInstances();
  
          LoadDBInfoCommand = new RelayCommand(LoadDBInfo);
      }
  
  
      public ObservableCollection&lt;DBInstance&gt; DBInstances
      {
          get;
          set;
      }
  
  
      public void LoadDBInstances()
      {
          ObservableCollection&lt;DBInstance&gt; dbInstances = new ObservableCollection&lt;DBInstance&gt;();
          DataTable dt = SmoApplication.EnumAvailableSqlServers(false);
  
          dbInstances.Add(new DBInstance { DBInstanceName = "fal-conversion\\mun2012ci" });
          dbInstances.Add(new DBInstance { DBInstanceName = "fal-conversion\\mun2014ci" });
  
          if (dt.Rows.Count &gt; 0)
          {
              foreach (DataRow dr in dt.Rows)
              {
                  dbInstances.Add(new DBInstance { DBInstanceName = dr["Name"].ToString() });
              }
          }
  
          DBInstances = dbInstances;
  
      }
  
  
      private DBInstance _selectedDBInstance;
  
  
      public DBInstance SelectedDBInstance
      {
          get
          {
              return _selectedDBInstance;
          }
  
          set
          {
              _selectedDBInstance = value;
              RaisePropertyChanged("SelectedDBInstance");
              //ClearComboBoxes();
  
          }
      }
  }
  }
  </code></pre>
  
  <p>Here is my Model code.  When I step through the code this method, <code>public string DBInstanceName</code>, gets executed multiple time.  I do not know why and it is seems wasteful to me.</p>
  
  <pre><code>namespace DatabaseTest.Model
  {
  public class RLFDatabaseTableModel { }
  
  
  public class DBInstance : INotifyPropertyChanged
  {
      private string strDBInstance;
  
  
      public override string ToString()
      {
          return strDBInstance;
      }
  
  
      public string DBInstanceName
      {
          get
          {
              return strDBInstance;
          }
  
          set
          {
              if (strDBInstance != value)
              {
                  strDBInstance = value;
                  RaisePropertyChanged("DBInstanceName");
              }
          }
      }
  
  
      public event PropertyChangedEventHandler PropertyChanged;
  
      private void RaisePropertyChanged(string property)
      {
          if (PropertyChanged != null)
          {
              PropertyChanged(this, new PropertyChangedEventArgs(property));
          }
      }
  }
  </code></pre>