50 Apps by Christmas: SilverKeys - Porting a Silverlight App to a Windows Store App

This article is part of the 50 Apps by Christmas series.

Graph of 50 app progress

I developed a Silverlight app a few years ago and I wanted to see how easy it would be to port to a Windows Store app. You can download free trial of SilverKeys for Windows 8.

The Original Silverlight App

Here’s a screenshot of the original Silverlight app:

Original Silverlight app screenshot

The app helps amateur composers try out different scales and also helps them understand what common chord progressions are often used.

The solution consisted of:

  • The Silverlight project
  • The “business logic” class library project (to calculate scales, chords, etc.)
  • A tests project

The Porting Process

The final Windows Store SilverKeys looks like this:

Windows Store version of SilverKeys screenshot

Whilst I’m not 100% happy with the UI, if the app is popular I will gradually improve it and also add some new features.

Reusing Code with Portable Class Libraries

I wanted to share the “business” logic throughout the Silverlight, Windows Store, and possible future Windows Phone apps; so I decided to create a Portable Class Library to do this. A Portable Class Library (PCL) allows you to share code and use it in different target runtimes such as Windows Store, Xbox, etc.

There were a few things I had to fix up, but nothing significant

In additional to the business logic I also pulled the viewmodel class & interface out of the Silverlight app and put that in the PCL so it can also be shared across platforms.

There were a few things I had to fix up due to the code now being restricted to the PCL subset, but nothing major or significant.

The next step was to re-integrate the PCL stuff back into the original Silverlight app which was pretty straightforward and didn’t cause any real problems

Porting the Unit Tests

I struggled initially with porting the unit tests, I tried a few different things. The tests were written using MSTest and I initially tried to port to xUnit.net which wasn’t necessary but I was treating it as learning exercise.

In the end I stayed with MSTest and created a class library project (.Net 4.5), referenced the “Microsoft.VisualStudio.QualityTools.UnitTestFramework” and also installed the RhinoMocks NuGet package as the original tests made use of mocking.

This completed the porting of the unit tests.

Creating the Windows Store App

The next step was to create a new Windows Store project, from which I referenced the PCL project.

I also ported (copy & pasted) the piano keyboard user control from the Silverlight app, fixed up any reference/namespace problems, and it worked without any substantial code modifications which was cool.

I also reused (the now PCL’d) viewmodel and data-bound the Windows 8 UI/controls to it. At this point the app doesn’t use any MVVM framework. The viewmodel is a hand-coded, simple implementation.

I then just had to do the Windows Store logos / assets to finalise version 1.

Next Steps

Now I have the PCL business logic and viewmodel working properly in both the Silverlight app and the Windows Store app, I can now create a Windows Phone version and I only have to create the UI.

Pingbacks and trackbacks (2)+

Add comment

Loading