Creating a Windows Phone Client
At the time of writing, you can't create apps for Windows Phone 7.x with Visual Studio 2012. However, you can still download and install the free Windows Phone 7.1 SDK, which offers Visual Studio Express for Windows Phone—a free, lightweight edition of the development environment for building mobile apps. In this environment, select File > New Project and create a new project of type Windows Phone application. The first thing to do is add a reference to the CustomersLibrary.dll assembly. Of course, in this case you don't add a reference to any projects; you simply use the compiled library. Similarly to Windows Store apps, Silverlight for Windows Phone doesn't have a DataGrid control. A good alternative is using a ListBox control and providing a data template to present items. In the XAML code editor, locate a Grid whose name is ContentPanel. Replace the content of that Grid with the code shown in Listing 11.
Listing 11Defining the user interface of the Windows Phone client.
<!--ContentPanel - place additional content here--> <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"> <ListBox ItemsSource="{Binding Customers}" Name="CustomersBox"> <ListBox.ItemTemplate> <DataTemplate> <Border BorderBrush="White" BorderThickness="2" Margin="3"> <StackPanel> <TextBlock Text="{Binding CompanyName}"/> <TextBlock Text="{Binding EmailAddress}"/> <TextBlock Text="{Binding PhysicalAddress}"/> <TextBlock Text="{Binding Phone}"/> </StackPanel> </Border> </DataTemplate> </ListBox.ItemTemplate> </ListBox> </Grid>
In the code-behind file of the page, you can simply create an instance of the ViewModel, as shown earlier in Listing 7. Running the application produces the result shown in Figure 9.
Figure 9 The Windows Phone client in action.
With this final example, it should be clear how we can write code once and share it across four different modern development platforms.