WCF RIA Services Data Binding

ComponentOne DataGrid for Silverlight's C1DataGrid control support direct binding to the WCF RIA services DomainDataSoure. There are two ways of doing so codelessly in XAML. You can bind directly to the DomainDataSource which works but involve some loss in filtering functionality, or you can use an Adaptor class to bind the grid.

You can bind the grid directly to the DomainDataSource, using XAML markup similar to the following:

<ria:DomainDataSource x:Name="_myDataSource" QueryName="GetProducts" PageSize="8">

                <ria:DomainDataSource.DomainContext>

                    <local:NorthwindContext/>

                </ria:DomainDataSource.DomainContext>

</ria:DomainDataSource>

 

<c1data:C1DataGrid x:Name="_dataGrid" ItemsSource="{Binding Data, ElementName=_myDataSource}">

You can bind the grid this way and it will work, but you will lose C1DataGrid's built-in filtering functionality because RIA services use a different filtering approach than standard CollectionView.

To retain all functionality you will need an additional class to "translate" the filtering information so RIA services can perform filtering; that’s when the C1RiaAdapter class comes into play. It performs the translations required for the C1DataGrid filtering to work with RIA.

You can use XAML markup similar to the following:

Indirect binding to DomainDataSource (binding through Adapter class)

<adapter:C1RiaAdapter x:Name="_adapter" DataGrid="{Binding ElementName=_dataGrid}">

            <ria:DomainDataSource x:Name="_myDataSource" QueryName="GetProducts" PageSize="8">

                <ria:DomainDataSource.DomainContext>

                    <local:NorthwindContext/>

                </ria:DomainDataSource.DomainContext>

            </ria:DomainDataSource>

</adapter:C1RiaAdapter>

 

 

<c1data:C1DataGrid x:Name="_dataGrid" ItemsSource="{Binding Data, ElementName=_adapter}">

If you bind the grid this way, you will get filtering support out of the box. Of course, if you do not need filtering support, you can always bind the grid directly without using C1RiaAdapter.

For an example, see the Binding the Grid to a WCF RIA Services Data Source topic.


Send us comments about this topic.
Copyright © GrapeCity, inc. All rights reserved.