【问题标题】:Bind combobox property of selected item in combobox to field将组合框中所选项目的组合框属性绑定到字段
【发布时间】:2016-07-25 19:16:17
【问题描述】:

我在 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&lt;String, String&gt; 场地。这对我来说似乎并不明显。所以我需要将所选项目的值绑定到我的字段,不知道该怎么做。

谢谢。

【问题讨论】:

    标签: c# silverlight


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-18
      • 1970-01-01
      • 1970-01-01
      • 2010-12-31
      相关资源
      最近更新 更多