My problem is that if I have objects with the same value in ValueMemberPath, then AutoCompleteBox selects the first item after selecting the right item. I have bound SelectedItem to a property, and I see that it is fired twice if there are several elements with the same value.
I bound my autorun to ObservableCollection Person objects.
public class Person
{
public int ID { get; set; }
public string Name { get; set; }
public string FullName
{
get
{
return Name + " - " + ID;
}
}
}
My XAML looks like this:
<StackPanel>
<inputtoolkit:AutoCompleteBox x:Name="autoCompleteBox" ValueMemberPath="Name" ItemsSource="{Binding Persons}" SelectedItem="{Binding SelectedPerson, Mode=TwoWay}">
<inputtoolkit:AutoCompleteBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding FullName}" FontSize="14" FontWeight="Bold"></TextBlock>
</DataTemplate>
</inputtoolkit:AutoCompleteBox.ItemTemplate>
</inputtoolkit:AutoCompleteBox>
<TextBlock x:Name="textBlock" Text="{Binding SelectedPerson.ID}"></TextBlock>
</StackPanel>
My Window_Loaded looks like this:
private void Window_Loaded(object sender, RoutedEventArgs e)
{
Persons = new ObservableCollection<Person>();
Persons.Add(new Person() { ID = 1, Name = "Person" });
Persons.Add(new Person() { ID = 2, Name = "Person" });
Persons.Add(new Person() { ID = 3, Name = "Person" });
Persons.Add(new Person() { ID = 4, Name = "Person" });
autoCompleteBox.DataContext = this;
textBlock.DataContext = this;
}
When I write "Per", 4 elements will be shown in DropDown. Now that I have selected the fourth, it is selected and updated. However, he returns to the first element. Is this a bug or an alleged behavior, and can someone help me with this problem?