将组合框中所选项目的组合框属性绑定到字段

时间:2016-07-25 10:27:47

标签: c# silverlight

我在ComboBox中遇到绑定问题。我在谷歌搜索过,但我找不到答案。

我有像这样的组合框的silverlight形式:

<ComboBox x:Name="FirmBox"
          Grid.Row="23"
          Grid.Column="1"
          Grid.ColumnSpan="2"
          Margin="5,5,5,0"
          SelectedValuePath="{Binding Path=Value, Mode=TwoWay}"
          SelectedItem="{Binding Path=Firm, Mode=TwoWay}">
    <ComboBox.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="{Binding Path=Value}"/>
                <TextBlock Text="{Binding Path=Key}"/>
            </StackPanel>
        </DataTemplate>
    </ComboBox.ItemTemplate>
</ComboBox>

ItemsSource是

ObservableCollection<KeyValue<String, KeyValue<String, String>>>

所以我已经弄清楚如何以正确的方式显示它,但我不知道如何将所选项目绑定到我的KeyValuePair<String, String> 领域。这对我来说似乎并不明显。所以我需要将所选项的值绑定到我的字段,并且不知道该怎么做。

谢谢。

1 个答案:

答案 0 :(得分:0)

解决方案一如既往地简单:

SelectedValuePath="Value"
SelectedValue="{Binding Path=Firm, Mode=TwoWay}">