Tomorrow is the Minnesota Developers Conference. I will be presenting on Building Line of Business Applications in Silverlight 3. Here is the code used in the demo and the slide deck.
Demo Code and Slide Deck
What does the demo code do? At a very high level this demo application shows some of the new features in Silverlight 3, surrounding the DataGrid and DataForm controls. But, first things first. This application was constructed using the Silverlight Business Application Template, which generates many files in the solution automatically. When reviewing the demo code, start with the DataDemo.xaml file in the View folder, and work to the supporting files it references. When running the application, all the demo features runs under the “Demo” tab in the application.
The data in this application is loaded locally in the Silverlight project via an XML file. The XML is an extract of the Employees table in the AdventureWorks database (available for download from CodePlex.com). Why did I take this approach? I started building this demo leveraging RIA services to get the data from the database to the Silverlight client as a more representative example of a line of business application.
However I abandoned that approach for a few reasons. The goal of the project is to show the DataGird and DataForm, and RIA services added more complexity than was needed to demo the controls. It also introduced a dependency on the database. Loading the data from an XML file, makes this project available for everyone, not just those who have the AdventureWorks database running. So yes, the whole data layer in this project is unrepresentative of a real data source in a line of business application. It is only a demo, you would definitely take a different approach for getting data in a real LOB application.
The demonstration of the new features available in the DataGrid control revolves around the new PagedCollectionView. The application implements Paging, Grouping and Filtering with this fantastic new object. Paging is supported in the UI through the use of the DataPager control. The DataGrid auto generates the columns on purpose, to show how data annotations in the SLEmployee data object affect the generation of these columns. If you like, you can set AutoGenerate = “False” on the DataGrid, and uncomment the data template columns that are already in the XAML.
The DataForm shows an example of Element-To-Element data binding, since the DataForm is bound to the SelectedItem in the DataGrid. The DataForm is also using automatic field generation, again to show how the Data Annotations in the SLEmployee object affect the display in the form. You can uncomment the data templates (and set AutoGenerateFields = “False”) to show the flexibility of the DataForm.
Be sure to review the SLEmployee data object. Data Annotations are new in Silverlight 3 and allow for the data object to control how the data is displayed, validated, and manipulated. Data annotations offer a tremendous amount of control to be owned by the business layer, yet automatically leveraged by the UI. Data Annotations are also very helpful when getting data via RIA services. But that is a different presentation.