在silverlight中,我用wcf ria server连接到数据库中
数据绑定控件与DomainDataSource绑定,TextBox中使用诸如{Binding ProductID,Mode=OneWay}的表达式提取数据。
我的程序的效果:
相关的xaml:
<sdk:DataGrid AutoGenerateColumns="True" MinHeight="100" HorizontalAlignment="Left"
Name="dataGridProducts" VerticalAlignment="Top" ItemsSource="{Binding ElementName=productDataSource, Path=Data}" />
<riaControls:DomainDataSource Name="productDataSource" LoadSize="20" QueryName="GetProducts" >
<riaControls:DomainDataSource.DomainContext>
<ds:NorthwindDomainContext/>
</riaControls:DomainDataSource.DomainContext>
</riaControls:DomainDataSource>
<sdk:DataPager Height="26" Name="dataPager1" PageSize="5" Width="200" Source="{Binding ElementName=productDataSource, Path=Data}" HorizontalAlignment="Left" />
<dataForm:DataForm x:Name="dataForm1" AutoCommit="False" AutoEdit="False" AutoGenerateFields="False"
Header="产品信息" CurrentItem="{Binding ElementName=dataGridProducts,Path=SelectedItem}" Width="400" HorizontalAlignment="Left">
<dataForm:DataForm.EditTemplate>
<DataTemplate>
<StackPanel>
<dataForm:DataField Label="产品编号:">
<TextBox IsReadOnly="True" Text="{Binding ProductID,Mode=OneWay}" />
</dataForm:DataField>
<dataForm:DataField Label="产品名称:">
<TextBox Text="{Binding ProductName,Mode=TwoWay}" />
</dataForm:DataField>
<dataForm:DataField Label="每单位数量:">
<TextBox Text="{Binding QuantityPerUnit,Mode=TwoWay}" />
</dataForm:DataField>
<dataForm:DataField Label="单价:">
<TextBox Text="{Binding UnitPrice,Mode=TwoWay}" />
</dataForm:DataField>
<dataForm:DataField Label="库存数量:">
<TextBox Text="{Binding UnitsInStock,Mode=TwoWay}" />
</dataForm:DataField>
</StackPanel>
</DataTemplate>
</dataForm:DataForm.EditTemplate>
</dataForm:DataForm>
我的是:SL5