Cross-platform App: Windows 8 + Windows Phone

The goal is to develop an application for Windows Store and Windows Phone maximizing code sharing.

We will need at least three projects:

  • ChessClock.Core: The logic and all common code and helpers the application can share, a Portable Class Library Project.
  • ChessClock.WindowsPhone: Windows Phone application project referencing the ChessClock.Core
  • ChessClock.WindowsStore: Windows Store application project referencing the ChessClock.Core

This is the current projects diagram:

projects diagram

Microsoft recommends to put ViewModels in the Portable Class Library, see Share functionality using Portable Class Libraries.

I prefer to put it together with the view because in my opinion view models should be only the glue between the view and the model, viewmodel should adapt the model to the view, and view models cannot contain logic but could contain for example a code that ask something to the user using a MessageBox or similar, and this is completly UI related.

Moreover this forces me to keep my viewModel as simple as possible, all the logic and data must be contained on Models.

Small part of my GameViewModel:

// Initialize commands
this.ReplayCommand = new RelayCommand(this.DoReplay);
this.PlayCommand = new RelayCommand(this.DoPlay);
this.PauseCommand = new RelayCommand(this.DoPause);
/// <summary>
/// Does the pause.
/// </summary>
private void DoPause()
/// <summary>
/// Does the play.
/// </summary>
private void DoPlay()
/// <summary>
/// Does the replay.
/// </summary>
private void DoReplay()
    // Ask continue or start a new game
    var questionResult = MessageBox.Show(string.Empty, Core.AppResources.NewGameGamePage, MessageBoxButton.OKCancel);
    if (questionResult == MessageBoxResult.OK)

Difficulties found:

The interface IValueConverter is contained in different assemblies because the current culture on Windows Store App is a string and in Windows Phone is a CultureInfo object.
Microsoft decided for some reason to change this…

// Windows Store:
public object Convert(object value, Type targetType, object parameter, string culture)
// Windows Phone:
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)

So far the converters will be duplicated and located on the platform specific projects, I hope to have an idea to solve this later.

The helpers that already exists where designed for Windows Phone, they make use of specific features as IsolatedStorage, or XNA to play sounds.
As this is not available for Windows Store a refactor of the helpers classes is necessary. The solution will be use interfaces inside the core, platform specific version will have to implement this interfaces.

– Cross-Platform Development
– Portable Class Library

1 thought on “Cross-platform App: Windows 8 + Windows Phone

  1. Pingback: My first Windows Store application is already published! | Juan Carlos Sánchez's Blog

Your feedback is important...

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.