我有以下来自 MSDN 的示例:
<Grid x:Name="LayoutRoot" Background="White">
<Grid.RowDefinitions>
<RowDefinition Height="25" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<riaControls:DomainDataSource Name="source" QueryName="GetProductsByColor" AutoLoad="true">
<riaControls:DomainDataSource.DomainContext>
<domain:ProductDomainContext />
</riaControls:DomainDataSource.DomainContext>
<riaControls:DomainDataSource.QueryParameters>
<riaControls:Parameter ParameterName="color" Value="{Binding ElementName=colorCombo, Path=SelectedItem.Content}" />
</riaControls:DomainDataSource.QueryParameters>
</riaControls:DomainDataSource>
<ComboBox Width="60" Grid.Row="0" x:Name="colorCombo">
<ComboBoxItem Content="Black" />
<ComboBoxItem Content="Blue" />
</ComboBox>
<data:DataGrid Grid.Row="1" ItemsSource="{Binding Data, ElementName=source}" />
</Grid>
好吧,您可以看到创建参数绑定的行已设置:
<riaControls:Parameter ParameterName="color" Value="{Binding ElementName=colorCombo, Path=SelectedItem.Content}" />
但是,如果我要使用代码尝试此操作,则它不起作用:
Binding binding = new Binding();
binding.ElementName = "colorCombo";
//binding.Source = this.colorCombo; also doesn't work!
binding.Path = new PropertyPath("SelectedItem.Content");
binding.Mode = BindingMode.OneWay;
Parameter param = new Parameter();
param.Value = binding;
source.QueryParameters.Clear();
source.QueryParameters.Add(param);
关于我做错了什么的任何想法?