Silverlight 3 application demonstrating Sample Data.

Displaying Sample Data in the WPF and Silverlight Designer for Visual Studio 2010 Beta2 is now very easy with the design time DesignData markup extension.
The below video is a complete tutorial for using Sample Data in your WPF and Silverlight applications. Please take a view few minutes to view it.
The Sample Application templates have many comments in them, walking you through Sample Data. Please take a few minutes and review the projects created by the Sample Application Templates.
Beta2 Template Information
For Beta2, you need to use these templates to consume sample data in your projects. The reason is the winfx.targets file for was not updated with the Sample Data Build Actions in time for Beta2.
These project files have been modified to include the DesignData Build Action for the Sample Data files. All Sample Data files must have their Build Action set to DesignData in the properties window.
These templates will not be required for the final version of Visual Studio 2010.
There are really two templates.
1. <Language> <Platform> Empty Application – this template consists of an empty project file and the added Build Action DesignData.
2. <Language> <Platform> Sample Application – this template consists of a sample application that has sample data files and a UserControl that demonstrates how to consume the sample data. It also includes the added Build Action DesignData.
WPF Templates
VB WPF Application DesignData – Empty VB.NET WPF Application template with sample data support.
VB WPF Application DesignData Sample – VB.NET Sample WPF Application that demonstrates consuming sample data.
CS WPF Application DesignData – Empty C# WPF Application template with sample data support.
CS WPF Application DesignData Sample – C# Sample WPF Application that demonstrates consuming sample data.
Silverlight Templates
VB SL Application DesignData – Empty VB.NET SL Application template with sample data support.
VB SL Application DesignData Sample – VB.NET Sample SL Application that demonstrates consuming sample data.
CS SL Application DesignData – Empty C# SL Application template with sample data support.
CS SL Application DesignData Sample – C# Sample SL Application that demonstrates consuming sample data.
Sample Application Template Usage
The WPF and Silverlight sample application template creates an application complete with sample data files, entity classes, a UserControl consuming the sample data files and
xmlns:d – How To Easily Add The d: Namespace
All design time properties live in a design time namespace that is part of this schema: http://schemas.microsoft.com/expression/blend/2008.
Examples of design time properties are, d:DesignWidth, d:DesignHeight, d:DesignInstance, d:DesignData, d:DataContext, d:Source.
In order to use the d: properties you must have a xmlns declaration in your XAML. In Visual Studio 2010 there is a very easy way to add it to a Window, UserControl or Page .xmal file.
If you select the root control, you’ll see a Root Size Mode button displayed in the lower right hand corner. Clicking this button changes the size mode of your root container from Auto to Fixed or from Fixed to Auto.
If the d: namespace has not been added to the root control yet, clicking this button will do it for you. In addition to the d: namespace, mc: is added and the mc:Ignorable is added also.

I have modified each of the starter templates below to automatically add this for you. However, as you add new Windows, Pages or UserControls, those templates may not have the d: namespace declarations, so the above trick comes in handy.
Adding a New Sample Data File
Open an existing Sample Data project or Create a new project using one of the Sample Data templates.
Add a resource dictionary to the project naming it <my entity class name>SampleData.xaml.
For example: Customer sample data file would be named, “CustomerSampleData.xaml”
The the file properties as pictured below:

Build Action: DesignData
Copy to Output Directory: Do not copy
Custom Too: <blank>
Editing a New Sample Data File
This is an example of a single instance sample data file.
<local:Customer
xmlns:local="clr-namespace:WPFApplication2"
Age="21" Email="jim@hotmail.com"
FirstName="Jim" LastName="Smith" />
Sample Data files allow you to construct your objects in XAML. You can set the required properties as illustrated above.
The below code illustrates how to create a collection of items in a sample data file.
<local:Customers xmlns:local="clr-namespace:WPFApplication2">
<local:Customer
Age="21" Email="jim@hotmail.com"
FirstName="Jim" LastName="Smith" />
<local:Customer
Age="22" Email="jane@hotmail.com"
FirstName="Jane" LastName="Smith" />
</local:Customers>
The above Customers class derives from the Generic List of Customer.
Consuming Sample Data in WPF
<!-- DataGrid Sample-->
<Grid d:DataContext="{d:DesignData Source=/SampleData/PeopleSampleData.xaml}"
Grid.Row="1" Margin="7">
<DataGrid ItemsSource="{Binding}"/>
</Grid>
Sample Data is exposed through the d:DataContext design time property. Design time properties are not compiled into your applications.
In WPF this is how you start at the root, navigate to SampleData folder and get the xaml file.
Consuming Sample Data in Silverlight
<!-- DataGrid Sample-->
<Grid d:DataContext="{d:DesignData Source=../SampleData/PeopleCollectionSampleData.xaml}"
Grid.Row="1" Margin="7">
<data:DataGrid ItemsSource="{Binding}"/>
</Grid>
In Silverlight you have to ../ up to the root, then navigate to SampleData folder and get the xaml file.
Slight difference between WPF and Silverlight.
Video
PLEASE view this short tutorial video. You will get a full and quick understanding of this great feature.
This video link supports right click, save as…
Sample Data Tutorial Video (22 minutes)
Installing Templates Using The Download
For VB.NET copy the download to:
C:\users\<your user name>\Documents\Visual Studio 2010\Templates\ProjectTemplates\Visual Basic
Unzip the download in this folder. You should have 4 zip files in the folder. You are ready to go.
For C# copy the download to:
C:\users\<your user name>\Documents\Visual Studio 2010\Templates\ProjectTemplates\Visual C#
Unzip the download in this folder. You should have 4 zip files in the folder. You are ready to go.
Downloads
After downloading one or both template downloads, you’ll need to rename the file extension from .doc to .zip. This is a requirement of WordPress.com.
Requires: Visual Studio 2010 Beta2
Silverlight Templates require: Silverlight 3
VB.NET Project Templates (61KB) (updated 10-28-2009)
C# Project Templates (58KB) (updated 10-28-2009)
Installing Templates From Within Visual Studio 2010 Beta2
The sample data templates are also be individually available on the Visual Studio Code Gallery.
To use a single template open the New Project Dialog and select the Online Templates tab at the bottom left. You can browse all available templates or search for “design” and all the templates will be listed.
Close
Hope you use and enjoy Sample Data in Visual Studio 2010 Beta2.
Gentle reminder, please watch the above video too.
Have a great day,
Just a grain of sand on the worlds beaches.