【问题标题】:How to make binding between comboBox item tag如何在组合框项目标签之间进行绑定
【发布时间】:2013-01-01 04:49:07
【问题描述】:

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

【问题讨论】:

    标签: wpf xaml dictionary combobox itemtemplate


    【解决方案1】:

    您可以绑定到 SelectedItem.Tag

    例子:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-08-19
      • 1970-01-01
      • 1970-01-01
      • 2019-12-27
      • 2016-02-12
      • 2011-05-20
      • 1970-01-01
      相关资源
      最近更新 更多