Documente Academic
Documente Profesional
Documente Cultură
NET Apps
Since the first release of the .NET Framework in 2002, developers have been building large-scale apps
with client-server architectures. These apps frequently adopt a layered approach, with business logic to
solve diverse and complex problems, accessed via desktop or web front-ends.
Today, C# and .NET are available across a diverse set of platforms in addition to Windows, including
Android and iOS with Xamarin, but also wearables like Apple Watch and Android Wear, consumer
electronics via Samsung Tizen, and even HoloLens.
In this blog post, I’ll show how to port business logic from WPF and build a phone- and tablet-friendly
mobile app for Android, iOS, and UWP. Existing C# code can often be re-used with minimal changes, and
the user interfaces can be built using Xamarin.Forms XAML to run across platforms.
WPF-to-mobile Example
Almost any .NET codebase, including Windows Forms, WPF, ASP.NET, and Silverlight, has sharable code
that can be ported to Xamarin.iOS, Xamarin.Android and UWP projects. By moving the shared code that
is platform agnostic to a .NET Standard Library (or a Shared Project) you can easily reference them in
mobile projects.
For this example, I am mobilizing an Expenses sample written a few years ago for a cloud-enabled WPF
app demo. The functionality works great on mobile, as you can see here:
The original Expenses app is a thick client written for desktop in WPF. The app helps users manage their
charges, create expense reports, and allows submitting for manager approvals. It connects to a WCF
backend and SQL Server for data storage, and looks like this:
The following sections detail how the legacy app code was analyzed, re-used, and adapted for mobile
deployment. You can download the original code and new mobile solution from my GitHub repo.
Analyze code for Mobilization
In general, any non-platform dependent code i.e. your Business Layer, Data Layer, Data Access Layer,
Service Access Layer, etc. can be shared across all platforms. To help you identify what code is sharable,
use the .NET Portability Analyzer tool. The .NET Portability Analyzer provides you with a detailed report
on how portable your program is across .NET platforms by analyzing assemblies. The Portability Analyzer
is offered as a Visual Studio Extension and as a console app. Once you install this extension, be sure to
check the platforms that you want to analyze in the settings and then right click on the project you want
to analyze and click “Analyze Project Portability”
It will generate a report like the one below from the Expenses WPF app.
The above shown consolidated report has the analysis of two libraries – Expenses.WPF and
Expenses.Data. From the report, apparently, Expenses.Data (data layer) is 100% shareable across all
platforms and as expected Expenses.WPF is about 80% shareable. These reports are available on my
GitHub repo – please refer the detailed sheet within the workbook to understand the libraries that aren’t
shareable.
The project MyExpenses.MobileAppService has controllers that inherit from TableController that provides
a RESTful endpoint and nicely abstracts away the code that supports offline data sync.
If you’re new to Azure Mobile Apps, these docs will help you get started quickly. However, if you wish to
retain the WCF service as-is on Azure, watch this video on Channel 9.
For detailed guidance on building Cross Platform apps using Xamarin.Forms, checkout our Getting-
Started guide.
To support offline sync for each of the tables, a corresponding Data Store is created that implements
IDataStore<T> interface – T being the Model object.