title: How can I avoid recursion when updating my ViewModel properties?
body: <p>In my View I have a <strong>slider</strong> and a <strong>combobox</strong>.</p>
  
  <p>When I <strong>change the slider</strong>, I want the combobox to change.</p>
  
  <p>When I <strong>change the combobox</strong>, I want the slider to change.</p>
  
  <p>I can udpate one or the other, but if I try to update both I get a <strong>StackOverflow error</strong> since one property keeps updating the other in an infinite loop.</p>
  
  <p>I've tried putting in a <strong>Recalculate()</strong> where the updating is done in one place, but still run into the recursion problem.</p>
  
  <p><strong>How can I have each control update the other without going into recursion?</strong></p>
  
  <p><strong>in View:</strong></p>
  
  <pre><code>&lt;ComboBox 
      ItemsSource="{Binding Customers}"
      ItemTemplate="{StaticResource CustomerComboBoxTemplate}"
      Margin="20"
      HorizontalAlignment="Left"
      SelectedItem="{Binding SelectedCustomer, Mode=TwoWay}"/&gt;
  
  
  &lt;Slider Minimum="0" 
          Maximum="{Binding HighestCustomerIndex, Mode=TwoWay}" 
          Value="{Binding SelectedCustomerIndex, Mode=TwoWay}"/&gt;
  </code></pre>
  
  <p><strong>in ViewModel:</strong></p>
  
  <pre><code>#region ViewModelProperty: SelectedCustomer
  private Customer _selectedCustomer;
  public Customer SelectedCustomer
  {
      get
      {
          return _selectedCustomer;
      }
  
      set
      {
          _selectedCustomer = value;
          OnPropertyChanged("SelectedCustomer");
          SelectedCustomerIndex = _customers.IndexOf(_selectedCustomer);
      }
  }
  #endregion
  
  #region ViewModelProperty: SelectedCustomerIndex
  private int _selectedCustomerIndex;
  public int SelectedCustomerIndex
  {
      get
      {
          return _selectedCustomerIndex;
      }
  
      set
      {
          _selectedCustomerIndex = value;
          OnPropertyChanged("SelectedCustomerIndex");
          SelectedCustomer = _customers[_selectedCustomerIndex];
      }
  }
  #endregion
  </code></pre>