0

我使用了 AutoCompleteBox 用户控件。我有一个类型的字典,Dictionary<int,string>其中包含 ID 和名称。我只想在 AutoCompleteBox 中显示名称。我可以做到

autoCompleteBox1.ItemsSource = dict.Values;

My problem is whenever any name is selected I want to retrieve the id associated with it. 但我不想向用户显示 ID,因为它们是出于内部目的。我该怎么做?

4

1 回答 1

2

我使用了以下内容:

<AutoCompleteBox ItemsSource="{Binding MyDict}" ValueMemberPath="Value">
   <AutoCompleteBox.ItemTemplate>
      <DataTemplate>
         <TextBlock Text={Binding Value}/>
      </DataTemplate>
   </AutoCompleteBox.ItemTemplate>
</AutoCompleteBox>
于 2010-07-02T13:11:05.917 回答