如何在comboBox项标签之间进行绑定

时间:2013-01-01 04:49:07

标签: wpf xaml dictionary combobox itemtemplate

我定义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(在组合中选择文本)==&gt;但我需要标签而不是文字...... :(

1 个答案:

答案 0 :(得分:2)

您可以绑定到SelectedItem.Tag

示例:

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