Build a Simple Application with .Net RIA Services (Silverlight 3) – Part 2

7 באפריל 2009

Build a Simple Application with .Net RIA Services (Silverlight 3) – Part 2

.Net RIA Services DomainDataSource This is the second post in a series of posts about building applications with Microsoft .Net RIA Services and Silverlight 3. In part 1 of this series I created a new application, created a simple data model and used the Domain Service and Domain Context to retrieve data and bind it to a DataGrid.
In this post we take it from that step, and replace the manual work with the DomainDataSource that provides some more advanced scenarios.

Use a DomainDataSource to easily connect the data

Remove the code that retrieves the data from the server. Open Views\HomePage.xaml and comment out all the code in the Page_Loaded method.

Instead of loading the data manually, add a DomainDataSource control to the page. To do this, add a reference to System.Windows.Ria.Controls.dll, and add the Xml namespace that relates to its contents:

<navigation:Page x:Class="BankApp.HomePage"



  Title="HomePage Page">




Add the DomainDataSource to the page

<navigation:Page x:Class="BankApp.HomePage"

  <Grid x:Name="LayoutRoot" Background="White">

    <ria:DomainDataSource x:Name="customersDataSource"








Reminder: After creating the DomainService in the server side, Visual Studio has generated a client side DomainContext that does all the magic of connecting to the server for us.

Assign the DomainContext to the DomainDataSource so it can use it to pull data from the server. To do that, add a local xml namespace:

<navigation:Page x:Class="BankApp.HomePage"




   Title="HomePage Page">




And do the assignment:


<ria:DomainDataSource x:Name="customersDataSource"





    <local:BankDomainContext />




The last thing we need to do is to bind the DataGrid to the DomainDataSource.

<data:DataGrid MinHeight="200"


              ItemsSource="{Binding Data, ElementName=customersDataSource}">


Run the application, and see how the data is being loaded in chunks according to the LoadSize property of the DomainDataSource.

Add a DataPager Control to enable paging through the data. To do that, add a reference to System.Windows.Controls.Data.DataForm.dll the following xml namespace:


Add the DataPager control and bind it to the DomainDataSource:

<data:DataGrid MinHeight="200" …>


<dataControls:DataPager PageSize="3"

              Source="{Binding Data, ElementName=customersDataSource}" />

If you now run the application, you should get a result similar to this:

DomainDataSource DataGrid DataPager


Data Grouping

Add Grouping support to the DataGrid. Add the following xml namespace:


Then, add a group descriptor to group the results by the property City.

<ria:DomainDataSource >


    <riaData:GroupDescriptor PropertyPath="City" />



The result should look like this:

DataGrid DomainDataSource Grouping GroupDescriptor

Data Sorting

To add sorting support, add a SortDescriptor:



    <riaData:SortDescriptor PropertyPath="CustomerID"

                            Direction="Descending" />



Rich Data Filtering

Add a dynamic filtering support based on a selected value of a CheckBox. Add a Checkbox above the DataGrid.

<CheckBox x:Name="chkBusiness"

          Content="Business Customer ?" />

<data:DataGrid x:Name="dataGrid" …> </data:DataGrid>

Add a FilterDescriptor that filters data according to the IsBusiness property of each item. Bind the FilterDescriptor  to the IsChecked property of the above checkbox.

<ria:DomainDataSource x:Name="customersDataSource" … >




      <riaData:FilterDescriptor PropertyPath="IsBusiness"


        <riaData:ControlParameter ControlName="chkBusiness"


                                  RefreshEventName="Click" />





Run the application, check and uncheck the checkbox, and see how the data is refreshed accordingly.

FilterDescriptors DomainDataSource


In this post we took on from where we left at Part 1 , and replaced the manual work needed to get the data from the server with the DomainDataSource that provides some more advanced scenarios. In the next post we’ll introduce the DataForm control and talk more about data validation.


Add comment
facebook linkedin twitter email


  1. Rachida Dukes9 באפריל 2009 ב 19:44

    This series is quite important to learn the new sivlerlight 3 and .Net RIA services. Please, keep adding more of this.
    Rachida Dukes

  2. nick_basdel30 ביוני 2009 ב 12:04 erolovirol
    [url=]erolovirol[/url] trrolol chivara
    dronc4tacelr trocals bovarelboc
    letogetlas chizelrel racrelc
    letolib liouli chiroacsit
    libocnaelc4t ricououc4to relrocnali
    monvic4tcoac sitgetmon cabocel

Comments are closed.