Sharing Code between Windows Store/Phone Apps using MVVM and PCL

I recently published an article on CodeProject.com about how developers can share their code base across Windows Phone and Windows Store apps using Model-View-ViewModel (MVVM) pattern and Portable Class Libraries (PCL).

If you are windows developer with experience of implementing MVVM or want to implement MVVM, I would request you to read the article and I would be happy to listen to your feedback.

Sharing Code Between Windows Phone and Windows Store Apps using MVVM and PCL

Excerpt from article:

As the business wants to expand its reach to different form factors and devices, a large number of developers build native apps across different platforms. One particular scenario is when developers wants to target Windows Phone and Windows Store platform. Unlike Android, developers have to create different projects inside Visual Studio for Windows Store and Windows Phone apps.

This article explains how developers can utilize the Model-View-ViewModel (MVVM) and .NET portable class libraries to create a common shared business logic across both platforms. We would not be able to cover MVVM introduction in this article, so I expect readers would already know about it, if you don’t know what MVVM is, I would recommend to read some intro articles first on MVVM before continuing further.

The App

For the sake of simplicity and learning, we are going to create a simple contact form app on both phone and tablet, which would look something like sketch below:

The Design

The design goal here is to move all the core business model, view-models, helpers and repositories in a separate portable class library which can be referenced by UI/View projects. The connection of view with view-models would be through data binding and commands etc.

One point worth mentioning here is that helpers and repositories from PCL would further communicate with external portable libraries like e.g. Http Client to perform network operation across both platform using same PCL dll. Now in real world you may not be able to achieve this 100% but it would work in many scenarios.

Implementation

So let’s start coding! we would create a simple yet naive approach of achieving the design above. Continue reading…

Most Popular Article on Code Project

cpArticle Last week I submitted an article, C# 4.0 Features, on CodeProject.com. From time to time, I have been posting some content related to C# 4.0 features on my blog, So what I did is that I formalize them as an article and submitted to code project. I shared my article with my colleagues, friends and MVPs and I got appreciation from them.

Today I received newsletter from Code Project which mentioned that my article is among most popular new articles from 4th May to 11th May 😀 with rating of 4.15/5.

image

Great, isn’t it? So that really boosts me up and hopefully I will continue writing articles on my blog, User Group blog and on different websites. To visit my profile on CodeProject, click here.