title: AutoCompleteBox - How to select a specific item from a collection of matching items?
body: <p>When using AutoCompleteBox - I have a list of items that have the matching display text - but different ID value.</p>
  <pre><code>[{Text:&quot;John&quot;,Id:1},{Text:&quot;John&quot;,Id:2},{Text:&quot;John Doe&quot;,Id:3}]
  </code></pre>
  <p><a href="https://i.stack.imgur.com/0onHV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0onHV.png" alt="enter image description here" /></a></p>
  <p>When I select the second row (John #2) -  the first value (John #1) is set to the <code>SelectedItem</code> property. When selecting a distinct value (John Doe #3) - it works correctly.</p>
  <p>My observation is that if there are more matching items - it always takes the first of them.</p>
  <p><strong>What can I do so that the correct item (John #2) is set to SelectedItem?</strong></p>
  <pre><code>&lt;controls2:AutoCompleteBox 
     EraseTextIfNull=&quot;False&quot;
     ValueMemberBinding=&quot;{Binding Converter={StaticResource AutocompleteItemTextConverter}}&quot;
     ItemsSource=&quot;{Binding TestItemSource, RelativeSource={RelativeSource TemplatedParent}}&quot;
     SelectedItem=&quot;{Binding TestSelectedItem,Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}&quot;
     Text=&quot;{Binding TestText, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}&quot; 
     ItemTemplate=&quot;{Binding Source={StaticResource TestItemTemplate}}&quot;
   /&gt;
  </code></pre>
  <p>ViewModel:</p>
  <pre><code>public class TestItemDto
  {
      public int Id { get; set; }
      public string Text { get; set; }
  }
  
  private ObservableCollection&lt;TestItemDto&gt; _testItemSource = new ObservableCollection&lt;TestItemDto&gt;
  {
      new TestItemDto
      {
          Id = 1,
          Text = &quot;John&quot;
      },
      new TestItemDto
      {
          Id = 2,
          Text = &quot;John&quot;
      },
      new TestItemDto
      {
          Id = 3,
          Text = &quot;John Doe&quot;
      },
  };
  
  public ObservableCollection&lt;TestItemDto&gt; TestItemSource
  {
      get =&gt; _testItemSource;
      set
      {
          _testItemSource = value;
      }
  }
  
  
  private string _testText;
  
  public string TestText
  {
      get { return _testText; }
      set
      {
          _testText = value;
          Console.WriteLine($&quot;TestText:{TestText}&quot;);
      }
  }
  
  private TestItemDto _testSelectedItem;
  
  public TestItemDto TestSelectedItem
  {
      get { return _testSelectedItem; }
      set
      {
          _testSelectedItem = value;
          Console.WriteLine($&quot;TestText:{TestSelectedItem?.Id}:{TestSelectedItem?.Text}&quot;);
      }
  }
  </code></pre>
  <p>Converter:</p>
  <pre><code>public class AutocompleteItemTextConverter : IValueConverter
  {
      public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
      {
          var adresarSearchResultItemDto = value as TestItemDto;
          return adresarSearchResultItemDto?.Text;
      }
      public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
      {
          return null;
      }
  }
  </code></pre>