簡體   English   中英

將組合框中的選定項目的組合框屬性綁定到字段

[英]Bind combobox property of selected item in combobox to field

我在ComboBox中綁定有問題。 我已經在Google中搜索過,所以一直找不到答案。

我有這樣的組合框的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>字段。 在我看來,這似乎並不明顯。 因此,我需要將所選項目的值綁定到我的字段,並且不知道該怎么做。

謝謝。

解決方案一如既往的簡單:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM