This sample builds upon the previous samples of the DevForce ObjectDataSource (ODS) control to add simple editing capabilities. The ObjectDataSource allows you to define and configure a data source directly in your XAML. The ODS supports asynchronous querying, paging, grouping, sorting and filtering of an EntityQuery.
If you have a lot of data to display and need to allow users to page, group, sort and filter the data. You prefer the simplicity of a drag and drop control.
The ObjectDataSource allows you to define and configure a data source directly in your XAML. The ODS supports asynchronous querying, paging, grouping, sorting and filtering of an EntityQuery.
This sample builds upon the previous samples, showing simple paging and grouping and filtering, by adding editing capabilities.
MainPage.xaml
The markup is similar to what we've seen in previous samples, but we've now included a simple DataForm, also bound to the ODS.
MainPage.xaml.cs
We see a little more logic in the code behind here than in previous samples. To note is the SaveChanges and RejectChanges calls made directly on the ObjectDataSource:
C# | _customersDataSource.SaveChanges(saveArgs => { if (saveArgs.Error != null) { MessageBox.Show(saveArgs.Error.Message); saveArgs.MarkErrorAsHandled(); } else { MessageBox.Show("Changes saved!"); } }); |
VB | _customersDataSource.SaveChanges(Sub(saveArgs) If saveArgs.Error IsNot Nothing Then MessageBox.Show(saveArgs.Error.Message) saveArgs.MarkErrorAsHandled() Else MessageBox.Show("Changes saved!") End If End Sub) |
Not shown in the sample, the ODS also contains a few dependency properties and visual states you can use to provide a better editing experience:
C# | public bool HasChanges { get; } public bool IsBusy { get; } public bool IsLoadingData { get; } public bool IsSavingChanges { get; } [TemplateVisualState(Name = "Enabled", GroupName = "CommonState")] [TemplateVisualState(Name = "Disabled", GroupName = "CommonState")] [TemplateVisualState(Name = "Idle", GroupName = "ActivityState")] [TemplateVisualState(Name = "Loading", GroupName = "ActivityState")] [TemplateVisualState(Name = "Saving", GroupName = "ActivityState")] |
VB | Public ReadOnly Property HasChanges() As Boolean Public ReadOnly Property IsBusy() As Boolean Public ReadOnly Property IsLoadingData() As Boolean Public ReadOnly Property IsSavingChanges() As Boolean <TemplateVisualState(Name = "Enabled", GroupName = "CommonState")> <TemplateVisualState(Name = "Disabled", GroupName = "CommonState")> <TemplateVisualState(Name = "Idle", GroupName = "ActivityState")> <TemplateVisualState(Name = "Loading", GroupName = "ActivityState")> <TemplateVisualState(Name = "Saving", GroupName = "ActivityState")> |