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:
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);
/// Does the pause.
private void DoPause()
/// Does the play.
private void DoPlay()
/// Does the replay.
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)
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