1

如何在网格的组合框中绑定从 WCF 返回的数据。组合框未处于编辑模式。我能够显示静态数据,但不能显示从 WCF 返回的数据。

4

2 回答 2

2

您可以使用RelativeSource在元素树示例中搜索所需的 DataContext/ViewModel/Page/UserControl 以查找在 ComBoxCollectionSource 附近定义的 DataGrid itemssource 的 ViewModel:

<ComboBox ItemsSource={Binding RelativeSource={RelativeSource AncestorType=sdk:DataGrid}, Path=DataContext.ComboBoxColloctionSource} />
于 2012-05-07T05:26:44.900 回答
0

我假设静态数据是您手动输入到 Items 属性中的内容。组合框的语法有点不同,但这里是:

<ComboBox ItemsSource="{Binding Path=<your collection>,Mode=OneTime}" SelectedValuePath="<id-field>" DisplayMemberPath="<display-field>" SelectedItem="{Binding Path=<your-property>,Mode=TwoWay}" />

上面以 PATH 结尾的参数只是将属性名称作为字符串。

编辑:如果你使用字典,你会使用:

<ComboBox ItemsSource="{Binding Path=<your dictionsry>,Mode=OneTime}" SelectedValuePath="Key" DisplayMemberPath="Value" SelectedItem="{Binding Path=<your-int-property>,Mode=TwoWay}" />
于 2012-05-07T05:22:47.457 回答