我有一个非常简单的设置,我无法在silverlight中工作。我订购了一系列OrderPayments。这些对象是实体框架模型的一部分,并通过WCF RIA服务公开。我可以完美地绑定Order类上的任何基本属性,但我想绑定到列表框以显示OrderPayments。这是ListBox的XAML。
<ListBox ItemsSource="{Binding Data.OrderPayments, ElementName=orderDataSource}"></ListBox>
列表框中没有任何内容,并且显示的订单至少有一个OrderPayment。 orderDataSource是包含Order的DomainDataSource。奇怪的是,我没有收到任何绑定错误,当我使用以下代码绑定到TextBlock时:
<TextBlock Text="{Binding Data.OrderPayments, ElementName=orderDataSource}" />
文本'OrderPayment'输出到屏幕。为了让Silverlight真正获取对象的引用,我还需要做些什么吗?
以下整个XAML:
<riaControls:DomainDataSource AutoLoad="True" Name="orderDataSource" QueryName="GetOrder">
<riaControls:DomainDataSource.QueryParameters>
<riaControls:Parameter ParameterName="orderid" Value="1" />
</riaControls:DomainDataSource.QueryParameters>
<riaControls:DomainDataSource.DomainContext>
<ds:CEWCPSDomainContext />
</riaControls:DomainDataSource.DomainContext>
</riaControls:DomainDataSource>
<StackPanel Orientation="Vertical" Margin="12">
<StackPanel Orientation="Horizontal">
<Button Width="100" Height="50" Content="Save & Return" Margin="0,0,12,12" />
<Button Width="100" Height="50" Content="Orders" Margin="0,0,12,12" />
<Button Width="100" Height="50" Content="Emails" Margin="0,0,12,12" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<dataForm:DataForm x:Name="dataForm1" Header="Order Contact Information"
AutoGenerateFields="False" AutoEdit="False" AutoCommit="False"
CurrentItem="{Binding Data, ElementName=orderDataSource}">
<dataForm:DataForm.EditTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<StackPanel>
<dataForm:DataField Label="First Name">
<TextBox Text="{Binding FirstName, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnExceptions=True }" />
</dataForm:DataField>
<dataForm:DataField Label="Last Name">
<TextBox Text="{Binding LastName, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnExceptions=True }"/>
</dataForm:DataField>
<dataForm:DataField Label="Organization">
<TextBox Text="{Binding Organization, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnExceptions=True }"/>
</dataForm:DataField>
<dataForm:DataField Label="Phone">
<TextBox Text="{Binding Phone, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnExceptions=True }"/>
</dataForm:DataField>
<dataForm:DataField Label="Fax">
<TextBox Text="{Binding Fax, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnExceptions=True }"/>
</dataForm:DataField>
<dataForm:DataField Label="Email">
<TextBox Text="{Binding Email, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnExceptions=True }"/>
</dataForm:DataField>
<dataForm:DataField Label="Address 1">
<TextBox Text="{Binding Address1, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnExceptions=True }"/>
</dataForm:DataField>
<dataForm:DataField Label="Address 2">
<TextBox Text="{Binding Address2, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnExceptions=True }"/>
</dataForm:DataField>
<dataForm:DataField Label="City">
<TextBox Text="{Binding City, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnExceptions=True }"/>
</dataForm:DataField>
<dataForm:DataField Label="State">
<TextBox Text="{Binding State, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnExceptions=True }"/>
</dataForm:DataField>
<StackPanel Orientation="Horizontal" Width="Auto">
<dataForm:DataField Label="Zip code">
<TextBox Text="{Binding Zip, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnExceptions=True }"/>
</dataForm:DataField>
<dataForm:DataField>
<TextBox Text="{Binding Zip4, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnExceptions=True }"/>
</dataForm:DataField>
</StackPanel>
<dataForm:DataField Label="Country">
<TextBox Text="{Binding Country, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnExceptions=True }"/>
</dataForm:DataField>
</StackPanel>
</StackPanel>
</DataTemplate>
</dataForm:DataForm.EditTemplate>
</dataForm:DataForm>
<StackPanel Orientation="Vertical">
<TextBlock FontWeight="Bold" FontSize="16" Text="Order Total / Payments" />
<TextBlock >
<Run Text="Order Total:" />
<Run Text="{Binding Data.OrderTotal, ElementName=orderDataSource}" />
</TextBlock>
<TextBlock Text="Payments" />
<TextBlock Text="{Binding Data.OrderPaymentItems, ElementName=orderDataSource}" />
<ListBox ItemsSource="{Binding Data.OrderPayments, ElementName=orderDataSource}">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Amount}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>
</StackPanel>
</StackPanel>
答案 0 :(得分:1)
默认情况下,WCF RIA Services不包含子实体。我需要将[Include()]放在Order对象的OrderPayments属性上。现在就像一个魅力。