2013-01-01 43 views
1

我定義了Dictionary,其中包含int作爲鍵和字符串作爲值Dictionary<int, string >。我做了ComboBoxItem之間,這Dictionary結合:如何在組合框項目標記之間進行綁定

<ComboBox ItemsSource="{Binding myDictionary}" > 
    <ComboBox.ItemTemplate> 
     <DataTemplate> 
      <TextBlock Text="{Binding Key}" Tag="{Binding Value}"/> 
     </DataTemplate> 
    </ComboBox.ItemTemplate> 
</ComboBox> 

現在,我想使項目選擇的標籤之間的綁定。我該怎麼做 ? 我知道如何做到這一點,以防萬一我想組合中的SelectedValue(獲得組合中選擇的文本)==>但我需要標籤而不是文本...... :(

回答

2

你可以結合SelectedItem.Tag

實施例:

<TextBlock Text="{Binding ElementName=cmbDictionary,Path=SelectedItem.Tag}"/>