Archives

Archives / 2010 / July
  • Silverlight DataGrid and DataPager Notes

    I need to write these things down somewhere...

    Brad's excellent tutorials and samples for learning Silverlight + RIA Services: http://blogs.msdn.com/b/brada/archive/2009/10/27/index-for-business-apps-example-for-silverlight-3-rtm-and-net-ria-services-july-update.aspx

    Scott's super blog post about columns and the DataGrid: http://blogs.msdn.com/b/scmorris/archive/2008/03/27/defining-columns-for-a-silverlight-datagrid.aspx (it's getting "old" but still rocks)

    To use the DataPager properly with a DomainDataSource, you have to set a sort order. The docs for the DataPager says:

    If you use the DataPager in an application with an Entity Framework data store, you must order the data returned by your queries for the DataPager to work correctly. The Entity Framework does not support paging of data without an OrderBy clause.

    This can be done with the SortDescriptor property of the DomainDataSource, for example:

    <riaControls:DomainDataSource  Name="dds" AutoLoad="True"         
                                   QueryName="GetVesselsQuery"                               
                                   LoadSize="20" LoadedData="dds_LoadedData">
        <riaControls:DomainDataSource.DomainContext>
            <Services:SomeDomainContext />
        </riaControls:DomainDataSource.DomainContext>
        <riaControls:DomainDataSource.SortDescriptors>
            <riaControls:SortDescriptor PropertyPath="name" Direction="Ascending"/>
        </riaControls:DomainDataSource.SortDescriptors>
    </riaControls:DomainDataSource>