Now we’ve reached the point where we stop talking and start playing around with some code. As concluded in the previous post on porting strategy, we’ll simply copy the code files from the Windows Phone project and create a new Windows 8 project. It won’t build right away, let alone run, but it’s a start.
The goal for this part is to have a Windows 8 project that does not build but has all the files from the Windows Phone project.
This post is a part in a series – you can find the full index here.
Creating the project
First and all we’ll create our Windows 8 Metro project.
We’ll use the Blank Application template. This is because we want to start clean and create our own thing. But after creating the project we find out that it’s not really empty…
They’ve given us a Common-folder as a getting started gift. It contains some help classes and styles meant to be used when adding new non-empty pages. There is also logic for handling Portrait and Landscape mode. Our app will not support portrait and we have no use for the other stuff, so we’ll remove this folder altogether.
Starting on our own code, we’ll add a class library called Sistaminuten.Common, to mimic the structure of the Windows Phone app.
Moving the files over
Let’s start by comparing the Windows Phone project with the Windows 8 project:
As you can see we have some files to copy. Except for the Views folder, we will copy everything over. The Windows Phone app was codenamed Peach, hence the namespace name.
The easiest way of copying all files over is to first put them in the folder of the Windows 8 project. Then click Show all files in Visual Studio 11, right click on the files and select Include in project.
Views and ViewModels
As you’ve probably seen already, there are two folders in the Windows Phone project called Views and ViewModels, which of course is a separation of concerns according to the MVVM pattern. MVVM is a pattern that will serve us well in this porting adventure. Please note that we are moving code only, we will not attempt to reuse the XAML, we want to rethink the UI.
If you have separated your views from your view models (and not filled you xaml.cs files with code), ripping out the views will be a painless exercise. But why remove the views? The answer is simple; the views in the phone app is built for a 4” screen and the slate will probably have a screen around 10”. The larger screen size gives us so many more possibilities in designing our views. To scale the UI of the Windows Phone app would simply look stupid. So – out with the old and bring in the new! What can be reused from the Windows Phone views are UI parts – like styles and templates.