将数据绑定到silverlight中的datagrid中的combobox

时间:2012-05-07 05:05:58

标签: silverlight datagrid datagridview combobox silverlight-5.0

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

2 个答案:

答案 0 :(得分:2)

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

<ComboBox ItemsSource={Binding RelativeSource={RelativeSource AncestorType=sdk:DataGrid}, Path=DataContext.ComboBoxColloctionSource} />

答案 1 :(得分: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}" />
相关问题