This sample illustrates how to use the DevForce ObjectDataSource (ODS) control. The ODS allows you to define a data source directly in your XAML, which UI controls, such as the DataGrid and DataForm, can then bind to. 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 ODS allows you to define a data source directly in your XAML, which UI controls, such as the DataGrid and DataForm, can then bind to. The ODS supports asynchronous querying, paging, grouping, sorting and filtering of an EntityQuery.
This sample shows you the simple mechanics of the ODS: how to define the ODS in XAML, and how to set the page size and sort fields.
MainPage.xaml
The ObjectDataSource is located in the IdeaBlade.Windows namespace in the IdeaBlade.Windows.SL assembly, so you will need to add a reference to this assembly in your project, and a namespace declaration within the page markup.
XML | xmlns:ib="clr-namespace:IdeaBlade.Windows;assembly=IdeaBlade.Windows.SL" |
In the sample you'll see a DataGrid and DataPager, in addition the the ObjectDataSource control. Note that the DataGrid's ItemSource and the DataPager's Source properties are both bound to the Data property of the ObjectDataSource.
Here's the markup for the ObjectDataSource control:
XML | <ib:ObjectDataSource x:Name="_customersDataSource" PageSize="20" LoadSize="40" AutoLoad="True" QueryName="Customers" > <ib:ObjectDataSource.EntityManager> <em:NorthwindIBEntities EntityServerError="EM_EntityServerError" Querying="EM_Querying" > </em:NorthwindIBEntities> </ib:ObjectDataSource.EntityManager> <ib:ObjectDataSource.SortDescriptors> <ib:SortDescriptor PropertyPath="CompanyName" Direction="Ascending" /> </ib:ObjectDataSource.SortDescriptors> </ib:ObjectDataSource> |
The PageSize indicates the number of items to be displayed on a page.
The LoadSize indicates the number of items to be loaded upon each page request. Setting the LoadSize to a value larger than the PageSize allows for “look ahead” caching of pages.
AutoLoad indicates whether the control will automatically execute the provided query once the control initializes or wait until the Load() method is called from code behind.
QueryName is the name of a property or method which will return the IEntityQuery serving as the data source. Since we didn't include a TypeName property indicating on which type the QueryName can be found, it's assumed to be on the EntityManager. In this sample, we're using the "Customers" property defined on the NorthwindIBEntities defined in the NorthwindIB entity model.
The EntityManager property indicates the EntityManager to be used. Since included here in markup, a new "NorthwindIBEntities" will be constructed. If you don't want a new EM, you have two options:
1) set the UseDefaultManager property to "True" to use the current DefaultManager, or
2) set the EntityManager property in code behind to the EM you wish to use
Note that we also provided a few event handlers to show what's happening as you run the sample.
SortDescriptors allows you to add one or more SortDescriptor elements to indicate the columns to be sorted.
(Grouping and filtering is shown in another code sample.)
Using the BusyIndicator
This sample also shows how the BusyIndicator control from the Silverlight Toolkit can be used with the ObjectDataSource. You'll bind the control to the IsBusy property of the ODS, as shown below:
XML | <tk:BusyIndicator IsBusy="{Binding IsBusy, ElementName=_customersDataSource}" > |