Silverlight+ WCF RIA Service 数据添加 求教
前台
<Grid x:Name="LayoutRoot"> <Button Content="Button" Height="23" Name="button3" Width="75" Click="button3_Click" /> <sdk:DataGrid x:Name="dg1" ItemsSource="{Binding Data, ElementName=TaskDetailDataSource}" DataContext="{Binding Data}" Width="500" Height="400"> <sdk:DataGrid.Columns> <sdk:DataGridTextColumn Header="ID" Width="120" Binding="{Binding TaskID, Mode=OneWay}" IsReadOnly="True"></sdk:DataGridTextColumn> <sdk:DataGridTextColumn Header="经度" Width="150" Binding="{Binding Longitude, Mode=TwoWay}" IsReadOnly="True"></sdk:DataGridTextColumn> <sdk:DataGridTextColumn Header="纬度" Width="150" Binding="{Binding Latitude, Mode=TwoWay}" IsReadOnly="True"></sdk:DataGridTextColumn> <sdk:DataGridTextColumn Header="排序" Width="120" Binding="{Binding Sort, Mode=TwoWay}" IsReadOnly="True"></sdk:DataGridTextColumn> </sdk:DataGrid.Columns> </sdk:DataGrid> <riaControls:DomainDataSource Name="TaskDetailDataSource" QueryName="GetTaskDetailQuery" LoadSize="20" AutoLoad="True" > <riaControls:DomainDataSource.DomainContext> <ds:ParkerDomainContext/> </riaControls:DomainDataSource.DomainContext> </riaControls:DomainDataSource> </Grid>
ParkerDomainContext _context = new ParkerDomainContext(); private void button3_Click(object sender, RoutedEventArgs e) { // ParkerDomainContext _context = (ParkerDomainContext)(TaskDetailDataSource.DataContext); TaskDetail taskDetail = new TaskDetail(); taskDetail.TaskID = 1; taskDetail.Latitude = 50; taskDetail.Longitude = 50; _context.TaskDetails.Add(taskDetail); //TaskDetailDataSource.DataContext = _context.TaskDetails; TaskDetailDataSource.SubmitChanges(); }