Build a Companion WP8 App for My Windows 8 App

Based on work from Andrew Byrne, Senior Programming Writer, Windows Phone, and Doug Rothaus, Senior Programming Writer, Windows and other sources.



Windows Phone 8 is built on the same shared core as Windows 8, and this means that developers have the opportunity to deliver applications to both, leveraging much of the same knowledge, tools, code and assets. This article explores the best practices on how to maximize your code reuse in building applications that target both Windows Phone and Windows 8.

The simultaneous release of Windows Phone 8 and Windows 8 gives developers the opportunity to build apps that reach a customer base projected to be in the hundreds of millions, in more than 190 countries. Windows Phone 8 and Windows 8 offer the consumer a set of devices that work great together. By developing apps that target both platforms, you’ll be catering to the needs of this consumer base and help grow your brand. Your Windows Store app will drive sales of your Windows Phone 8 app, and vice versa.

Windows Phone 8 apps and Windows Store apps share a consistent user experience. There’s consistency in UI design, from the use of tiles, the rich touch interface, the app bar, and navigation. This consistency simplifies app design on both platforms, because you can "talk in the same language" in both environments. When it comes to implementation, the controls and API used to build these apps are similar, and we've adopted a common API surface area that will enable code sharing for a lot of scenarios.

The Windows Phone API has evolved in this release to allow you to create apps with more features than ever before. We've also taken strides to enable you to share code across Windows Phone 8 and Windows 8. This release is a significant step along the path of platform convergence with Windows 8. In this release of Windows Phone 8, we’ve made serious investments to align with Windows 8 by adopting Windows Runtime API, supporting native development, and sharing the .NET engine.

Developers can choose the right technologies for their app. In Windows Phone 8, you can use C#, VB, or C++ to develop XAML apps, native apps and games, or hybrid (C#/VB and C++) apps for both platforms. You can also use JavaScript in the context of a web browser control.


Before you dive into Visual Studio 2012 to build your project it is important to understand your skills, particular situation, objectives and what you are trying to achieve. Answering these questions will set you on a path that is more effective and yields best results?

What type of developer are you?

New to the Platform Typically you would have no existing apps and can’t wait to build and ship your app to Windows Phone Store or Windows Store. In this case the suggestion is that as a beginner you grab the free tools and start exploring building for either platform. You can explore:

imageSeasoned in Windows Phone App    
You already built Windows Phone Apps and now want to build apps for Windows Phone 8 and Windows 8. You will find a lot of similarities when you develop your apps for both platforms. To get started explore:

imageSeasoned in Windows Store App
You already built Windows Store apps and now want to build apps for Windows Phone 8 and Windows 8. You will find a lot of similarities when you develop your apps for both platforms. You can get started by exploring these sources:

imageSeasoned in another Platform
You’ve built apps for other platforms, and want to ship them or port them to Windows Phone 8 and Windows 8. Many of the programming concepts will be familiar. Both platforms support C++, and the tools have templates to help you get started. To learn more explore:

imageGames Creator from another Platform
You’ve built games for another platforms and want to port them to Windows Phone 8 and Windows 8. We’ve invested significantly in native gaming support on Windows Phone 8 and this will make it possible for you to port your existing games to both Windows Phone 8 and Windows 8. Check these resources:


After choosing your approach, based on what type of developer you fall under, you can now decide what choices to make to maximize code reuse in your apps. As a developer, you want to streamline your development and make maintaining your app efficient. When building an app for Windows Phone 8 and Windows 8, you should look for opportunities to share code, designs, and assets as much as possible so that you maximize the return on your investment.



Considering choosing any of the following techniques separate or combined.

Separate UI and App Logic Using MVVM Pattern

This guidance is applicable to many app types, but particularly to apps that have a XAML UI. Separation allows you to write the app logic and to concentrate on user experience design separately. An added benefit is that your app logic is more likely to be common for your app on both platforms, and therefore is a great candidate for code sharing using the rest of the techniques described here. Model-View-ViewModel (MVVM) is a great way to achieve this separation.

Share Functionality Using Portable Class Libraries

Windows Phone 8 and Windows 8 share the same .NET Framework engine. In a XAML app, most of your app logic will be written in managed code. If you are using the MVVM design pattern, you have the potential to share your ViewModel and potentially your model. Note that Portable Class Libraries are a .NET Framework concept and don’t support C++.

Share Code with Add As Link

Use this technique for code that is non-portable and therefore can’t be implemented in a Portable Class Library. For example, Windows Phone 8 and Windows 8 can use the common Windows Runtime API surface to harness the power of each platform for networking, proximity, in-app purchase, and many other features. Portable Class Libraries don’t support Windows Runtime API. Instead, you can abstract this non-portable code, which is common to both platforms, into a class that can be shared using Add as Link in Visual Studio. In C++ projects files are added to projects as linked files by default.

Share Using Windows Runtime Components

In addition to consuming the common Windows Runtime API available on both platforms, you can write your own Windows Runtime Component to make your functionality available in all supported languages. This can be written in C++ and consumed by C# or VB. This is a very useful technique for language interoperability or for when you want to write compute-intensive code in C++ and use it in all languages.

Sharing XAML UI

The UI in Windows Phone 8 and Windows 8 is written in XAML. However, the XAML implementations are not portable between the platforms. But you can isolate some of your custom basic UI building blocks into UserControls and share those classes as linked files that will be compiled for each platform. This technique is limited and should be used only for simple, reusable parts of your UI. The core of your UI should be built and tailored separately for each platform.

Conditional Compilation with Preprocessor Directives

If you have functionality that’s implemented differently for Windows Phone 8 and Windows 8, you can use conditional compilation to compile the code suitably for each platform. You can’t use conditional compilation in a Portable Class Library. How much you adopt this technique will depend on your app complexity, but it can lead to more difficult code maintenance if used extensively.


The PixPresenter sample demonstrates code sharing techniques you can use when developing an app for Windows 8 and Windows Phone 8. It is a photo-sharing app that enables you to connect to another device using Proximity (NFC) and a tap gesture, and then send pictures back and forth between the connected devices.

Sharing XAML UI

To run this sample, you must have the Windows Phone SDK 8.0 installed. You can download it from

  1. Extract the zipped files into a local directory.
  2. Start Visual Studio 2012 and select File > Open > Project/Solution.
  3. Go to the directory in which you unzipped the sample. Double-click the Visual Studio 2012 solution file named PixPresenterAll.sln.
  4. Select Build > Rebuild Solution to build the sample.

This solution contains a Portable Class Library. Portable Class Library projects can’t be created or compiled using the Express versions of Visual Studio. Use Visual Studio 2012 Pro, Enterprise or Ultimate to build this sample. You can add a reference to a Portable Class Library in all versions of Visual Studio, including Express. You can download a trial version of Visual Studio 2012 Pro here.