2011-03-02 1 views
3

내 문제는 ValueMemberPath에 같은 값을 가진 개체가있는 경우 AutoCompleteBox가 올바른 항목을 선택한 후 첫 번째 항목을 선택한다는 것입니다. SelectedItem을 Property에 바인딩했는데 동일한 값을 가진 항목이 여러 개인 경우 두 번 해고되는 것을 볼 수 있습니다.동일한 값을 가진 항목이 여러 개있을 때 AutoCompleteBox 문제가 발생했습니다.

필자의 AutoCompleteBox를 Person 객체의 ObservableCollection에 바인딩했습니다.

public class Person 
{ 
    public int ID { get; set; } 
    public string Name { get; set; } 
    public string FullName 
    { 
     get 
     { 
      return Name + " - " + ID; 
     } 

    } 
} 

내 XAML은 다음과 같습니다

<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> 

내 Window_Loaded은 다음과 같습니다 : 나는 "당"쓸 때 4 개 항목이 드롭 다운에 표시됩니다

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; 
    } 

. 이제 네 번째를 선택하면 선택되고 바인딩이 업데이트됩니다. 그러나 그런 다음 첫 번째 항목으로 돌아갑니다. 이 버그 또는 의도 된 동작이며 누구든지이 문제를 도와 줄 수 있습니까?

+1

사용자가 어쨌든 차이점을 어떻게 알 수 있습니까? –

+0

예, 사용자가 동일한 값의 목록에서 선택하는 방법을 설명 할 수 있다면 도움이 될 것이라고 생각합니다. –

+1

우리가 더 많은 정보를 얻지 못한다면 말하기가 어렵습니다. 하지만이 코드를 올바르게 이해한다면 ValueMemberPath = "Name"은 ValueMemberPath = "ID"이어야합니다. – ingo

답변

1

동일한 문제가 있습니다. 나는 아직 시도하지 않았지만이 링크를 발견하고 해결책을 찾는다.
http://www.yumasoft.com/node/45

편집
난 그냥이 일을한다는 것을 확인했다.

사용자가 차이점을 어떻게 설명하는지 묻는 설명입니다. ItemTemplate 공급자는 TextBox 부분에 표시된 것보다 더 자세한 정보를 제공합니다. 이를 통해 사용자는 사용할 레코드를 결정할 수 있습니다.