简体   繁体   中英

Bind combobox property of selected item in combobox to field

I have an issue with binding in ComboBox. I have searched in Google and so, but I haven't been able to find the answer.

I have silverlight form with combobox like this:

<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>

And the ItemsSource is an

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

So I've figured out how to display this in right way, but I don't know how to bind the selected item to my KeyValuePair<String, String> field. That does not seem obvious to me. So I need to bind the value of selected item to my field and don't know how to do it.

Thank you.

The solution was simple as always:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM