title: How do you bind a ComboBox's SelectedItem to an object that is a copy of an item from ItemsSource?
body: <p>I'm using the MVVM pattern with WPF and have run into a problem, which I can simplify to the following:</p>
  
  <p>I have a CardType model.</p>
  
  <pre><code>public class CardType
  {
      public int Id { get; set; }
      public string Name { get; set; }
  }
  </code></pre>
  
  <p>And I have a viewmodel that consumes CardType.</p>
  
  <pre><code>public class ViewModel : INotifyPropertyChanged
  {
      private CardType selectedCardType;
      public CardType SelectedCardType
      {
          get { return selectedCardType; }
          set
          {
              selectedCardType = value;
              OnPropertyChanged(nameof(SelectedCardType));
          }
      }
  
      public IEnumerable&lt;CardType&gt; CardTypes { get; set; } 
  
      // ... and so on ...
  }
  </code></pre>
  
  <p>My XAML has a ComboBox that bases its items on CardTypes and should preselect an item based on SelectedCardType.</p>
  
  <pre><code>&lt;ComboBox ItemsSource="{Binding CardTypes}"
            DisplayMemberPath="Name"
            SelectedItem="{Binding SelectedCardType}"/&gt;
  </code></pre>
  
  <p>For reasons outside of my control, the SelectedCardType object will be a <strong>reference-unequal copy</strong> of the item in CardTypes.  Therefore WPF fails to match the SelectedItem to an item in ItemsSource, and when I run the app, the ComboBox initially appears with no item selected.</p>
  
  <p>I tried overriding the Equals() and GetHashCode() methods on CardType, but WPF still fails to match the items.</p>
  
  <p>Given my peculiar constraints, how can I get ComboBox to select the correct item?</p>