SlideShare a Scribd company logo
Building a real-world
cross-platform app with
Xamarin and MVVM
Gill Cleeren
@gillcleeren
Gill Cleeren
Microsoft MVP & RD
Solution Architect
@gillcleeren
www.snowball.be
gill@snowball.be
Xamarin, HTML5, WPF, social
and Windows development
http://gicl.me/mypscourses
Overview
We’ll start with
Looking at the final app
Understand the concepts of the architecture
Understand MvvmCross
And then…
We’ll explore the architecture
We’ll look at the shared blocks
We’ll see the Android and iOS apps
And we’ll add some tests
And then we’ll all go home. Or get a drink.
The app we’ll be using
• My Trains
• Works on iOS and Android
• Searching train journeys
• View journey details
• Add to My Journeys
• Settings
• Based on MvvmCross framework
Code available on GitHub via
https://github.com/GillCleeren/MyTrains
Concepts of the architecture
Data Binding
UI Element
UI Property
Object
Property
Data
Binding
3
4
1
2
Binding target Binding source
The Data Context
From: London
To: Manchester
Departure: 11:00
Save
Object
We can bind to…
Single
objects
Collections
<TextView
android:textSize="18dp"
local:MvxBind="Text SelectedJourney.JourneyDate" />
Binding in Android (using MvvmCross)
var set = this.CreateBindingSet<JourneyDetailView,
JourneyDetailViewModel>();
set.Bind(DepartureDateLabel)
.To(vm => vm.SelectedJourney.JourneyDate));
Binding in iOS (using MvvmCross)
public class MyModel : INotifyPropertyChanged
{
private string _myProperty;
public string MyProperty
{
get { return _myProperty; }
set
{
_myProperty = value;
PropertyChanged
(this, new PropertyChangedEventArgs("MyProperty");
}
}
public event PropertyChangedEventHandler PropertyChanged;
}
Change notifications
Binding modes
OneTime OneWay
TwoWay OneWayToSource
<EditText
local:MvxBind="Text NumberOfTravellers, Mode=TwoWay" />
Binding modes in code
public class DateTimeToDayConverter : MvxValueConverter<DateTime,
string>
{
protected override string Convert(DateTime value, Type
targetType, object parameter, CultureInfo culture)
{
return value.ToString("MMM dd, yyyy");
}
}
<TextView
local:MvxBind="Text SelectedJourney.JourneyDate,
Converter=DateTimeToDay" />
Converters
And now for something completely MVVM!
MVVM, c’est quoi?
Architectural
pattern
Based on MVC
Data binding
&
Commanding
XAML
What we all did when we were young…
Write code in code-behind… Lots of it.
Data Model
View
“View” code
Code-Behind
Event Handlers
Writing testable code however, is becoming
the norm. Finally. Courtesy of MVVM.
Data Model
View
“View code”
Code-Behind
View Model
State +
Operations
Change
notification
Data-binding
and commands
public class JourneyDetailViewModel : MvxViewModel, IJourneyDetailViewModel
{
public Journey SelectedJourney
{
get { return _selectedJourney; }
set
{
_selectedJourney = value;
RaisePropertyChanged(() => SelectedJourney);
}
}
public MvxCommand CloseCommand
{
get { return new MvxCommand(() => Close(this)); }
}
}
Sample view model
Real world apps with Xamarin and MVVM
The powers of MvvmCross
Open source Promotes sharing
of code
iOS, Android, XF,
WPF…
MvvmCross features
Data binding IOC built-in Rich support for
plugins
Real world apps with Xamarin and MVVM
Exploring the architecture
Core project
(Shared)
UI projects
Repositories
Data Services
View Models
Other services
Models
Remote service
iOS Android
Windows
UWP
Mvvm
Cross
MvvmCross
Core project
(Shared)
UI projects
Repositories
Data Services
View Models
Other services
Models
Remote service
iOS Android
Windows
UWP
Mvvm
Cross
MvvmCross
Unit test project
Shared code
Android project
iOS project
Solution and Projects
The Core Project
Portable class library Shared Project Standard Library Project
Required NuGet Packages
Demo
Looking at the solution and the MvvmCross packages
Exploring the Core project
Important classes to start with…
App AppStart
Demo
Model Classes
POCO
Client-side
model
Sometimes
needs to be
mapped
public class User
{
public int UserId { get; set; }
public string UserName { get; set; }
public string Email { get; set; }
public string Password { get; set; }
}
Sample model
Repository layer
Actual data
retrieval
Layer between
data and app
CRUD-based
Single model Asynchronous
Maps to local
models
public class SavedJourneyRepository : ISavedJourneyRepository
{
public async Task<IEnumerable<SavedJourney>>
GetSavedJourneyForUser(int userId)
{
...
}
public async Task AddSavedJourney
(int userId, int journeyId, int numberOfTravellers)
{
...
}
}
Sample repository
Services
Layer between
repo and VMs
Unit of
functionality
Business rules
Abstractions
with
interfaces
public class CityDataService: ICityDataService
{
public async Task<List<City>> GetAllCities()
{
...
}
public async Task<City> GetCityById(int cityId)
{
...
}
}
Sample data service
Demo
Exploring the Core project
IOC & Service location in MvvmCross
Central
location for
dependencies
Useful for
testing
Built into
MvvmCross
Mvx.RegisterSingleton<ICityDataService>
(new CityDataService());
var cityDataService = Mvx.Resolve<ICityDataService>();
Registering with the IOC container
public class UserDataService: IUserDataService
{
private readonly IUserRepository _userRepository;
public UserDataService(IUserRepository userRepository)
{
_userRepository = userRepository;
}
}
Registering with the IOC container
We can use the IOC container to
plug a different implementation
into the core project
per platform.
Demo
The Mvx service locator in use
View Models
State Operations
public class JourneyDetailViewModel :
MvxViewModel, IJourneyDetailViewModel
{
public Journey SelectedJourney
{
get { return _selectedJourney; }
set
{
_selectedJourney = value;
RaisePropertyChanged(() => SelectedJourney);
}
}
}
View Model
public class JourneyDetailViewModel :
MvxViewModel, IJourneyDetailViewModel
{
public MvxCommand CloseCommand { get; set; }
public JourneyDetailViewModel()
{
CloseCommand = new MvxCommand(() =>
{
Close(this);
});
}
}
View Model
NavigateToSearchJourneyCommand =
new MvxCommand(() =>
ShowViewModel<SearchJourneyViewModel>());
ViewModel navigation
Demo
View Models
Moving to the Android app
The Android Project
Packages in the Android app
MvvmCross Plugins
Xamarin
Android support
packages
Starting the actual Android app
Android app Core
Setup App
Initialize()
AppStart()
First VM()
public class Setup: MvxAndroidSetup
{
public Setup(Context applicationContext)
:base(applicationContext)
{ }
protected override IMvxApplication CreateApp()
{
return new Core.App();
}
}
ViewModel navigation
[Activity(
Label = "@string/ApplicationName", MainLauncher = true)]
public class SplashScreen : MvxSplashScreenActivity
{
public SplashScreen()
: base(Resource.Layout.SplashScreen)
{
}
}
Splash screen
Demo
Looking at the Android app
[MvxFragment(typeof(MainViewModel), Resource.Id.content_frame, true)]
[Register("mytrains.droid.views.JourneyDetailsFragment")]
public class JourneyDetailsFragment: MvxFragment<JourneyDetailViewModel>
{
public override View OnCreateView
(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
base.OnCreateView(inflater, container, savedInstanceState);
return this.BindingInflate(Resource.Layout.JourneyDetailsView, null);
}
}
Detail page (fragment)
<Mvx.MvxListView
android:id="@+id/searchresults_list”
local:MvxItemTemplate="@layout/item_journey_search_result"
local:MvxBind="ItemsSource Journeys;
ItemClick ShowJourneyDetailsCommand" />
List page
Creating the different Android views
Demo
Creating the DrawerLayout navigation
Main Activity
MenuFragment
Search
Journeys
Fragment
Demo
Adding the DrawerLayout navigation
And now:
iOS
The iOS Project
Packages in the iOS app
MvvmCross Plugins
Application Startup
iOS app Core
Setup App
Initialize()
AppStart()
First VM()
public class Setup: MvxIosSetup
{
public Setup(MvxApplicationDelegate applicationDelegate, UIWindow window)
: base(applicationDelegate, window)
{
_applicationDelegate = applicationDelegate;
_window = window;
}
protected override IMvxApplication CreateApp()
{
return new App();
}
protected override void InitializeIoC()
{
base.InitializeIoC();
Mvx.RegisterSingleton<IDialogService>(() => new DialogService());
}
}
Setup
The Application Storyboard
Demo
Looking at the iOS app structure
public partial class JourneyDetailView : BaseView
{
protected JourneyDetailViewModel JourneyDetailViewModel
=> ViewModel as JourneyDetailViewModel;
public JourneyDetailView(IntPtr handle) : base(handle)
{
}
protected override void CreateBindings()
{
}
}
Sample view controller
Building Blocks
UITableView
TableViewSource
Cell
Creating the different iOS views
Demo
Main View Model
Tab Navigation in iOS
Search Journey
View Model
Saved Journeys
View Model
Settings View
Model
Demo
Adding the Tab navigation
Working with plug-ins
What are plug-ins for MvvmCross?
Add
functionality
Work because
of IOC
Can be shared
or specific for
a platform
Extension
point
NuGet
Existing plugins
Database
(Sqlite)
Email Files
Localization Messenger Location
Demo
Showing web pages with the Browser plugin
Putting our
architecture
to the test
Unit tests – Why?
Bugs No fear of change Better software
Demo
Testing the view models and the services
Summary
• MVVM and MvvmCross promote reuse
• iOS and Android app can share more code
• Architecture can be your starting point
Take a look at the code and tweet @gillcleeren
for questions or remarks!
And watch the full Pluralsight course via
https://www.pluralsight.com/courses/mvvm-based-
architecture-xamarin-mobile-apps
Thank you!
Q&A
Building a real-world
cross-platform app with
Xamarin and MVVM
Gill Cleeren
@gillcleeren

More Related Content

PPTX
Continuous integration and delivery with Xamarin and VSTS
PDF
Midas - on-the-fly schema migration tool for MongoDB.
PPTX
Visual Studio 2015 - Lançamento está próximo
PDF
Microservices pattern language (microxchg microxchg2016)
PDF
VMworld 2013: vCloud Hybrid Service Jump Start Part Five of Five: Deep Dive i...
PDF
What makes xamarin the best choice for multiplatform app development
PDF
React native vs react js
PDF
[Td 2015]general session 세상을 품은 플랫폼과 그 가능성에 대하여(기술에반젤리스트)
Continuous integration and delivery with Xamarin and VSTS
Midas - on-the-fly schema migration tool for MongoDB.
Visual Studio 2015 - Lançamento está próximo
Microservices pattern language (microxchg microxchg2016)
VMworld 2013: vCloud Hybrid Service Jump Start Part Five of Five: Deep Dive i...
What makes xamarin the best choice for multiplatform app development
React native vs react js
[Td 2015]general session 세상을 품은 플랫폼과 그 가능성에 대하여(기술에반젤리스트)

What's hot (20)

PDF
Angular 12 brought several new features to the table
PDF
App sec and quality london - may 2016 - v0.5
PPTX
DevOps Turkey Test Automation with Docker and Seleniumhub
PPTX
Test Automation Workshop with BDD Approach
PDF
Ibm empresa movil
PPTX
Developing With Data Technologies
PPTX
Azure Deployment(Seattle)
PPTX
harePoint Framework Webinar Series: Consume Graph APIs in SharePoint Framework
PPTX
Windows Phone 7 Unleashed Session 2
PDF
IBM Bluemix Tech Meetup 18-02-2015
PPTX
ASP.NET Core 2.1: The Future of Web Apps
PDF
Voxxed Days Thesaloniki 2016 - A journey to Open Source Technologies on Azure
PPT
Presentation 1 open source tools in continuous integration environment v1.0
PDF
5 best Java Frameworks
PDF
Effective testing of rich internet applications
PDF
Accelerating DevOps at the SF DevOps MeetUp
PPTX
Microsoft Skills Bootcamp - The power of GitHub and Azure
PPTX
Azure DevOps for Developers
PPTX
Modernizing Twitter for Windows as a Progressive Web App
PPTX
Microsoft DevOps Solution - DevOps
Angular 12 brought several new features to the table
App sec and quality london - may 2016 - v0.5
DevOps Turkey Test Automation with Docker and Seleniumhub
Test Automation Workshop with BDD Approach
Ibm empresa movil
Developing With Data Technologies
Azure Deployment(Seattle)
harePoint Framework Webinar Series: Consume Graph APIs in SharePoint Framework
Windows Phone 7 Unleashed Session 2
IBM Bluemix Tech Meetup 18-02-2015
ASP.NET Core 2.1: The Future of Web Apps
Voxxed Days Thesaloniki 2016 - A journey to Open Source Technologies on Azure
Presentation 1 open source tools in continuous integration environment v1.0
5 best Java Frameworks
Effective testing of rich internet applications
Accelerating DevOps at the SF DevOps MeetUp
Microsoft Skills Bootcamp - The power of GitHub and Azure
Azure DevOps for Developers
Modernizing Twitter for Windows as a Progressive Web App
Microsoft DevOps Solution - DevOps
Ad

Viewers also liked (11)

PPTX
Bootstrap: the full overview
PPTX
Building your first iOS app using Xamarin
PPTX
Building your first android app using Xamarin
PDF
MvvmCross Quickstart
PPTX
DevOps for Your Mobile App
PDF
Developing native iOS & Android apps in c# with xamarin
PPTX
Mobile development strategies with MVVM
PDF
Continuous Integration & deployment for your Xamarin app
PDF
Cross Platform, Native Mobile Application Development Using Xamarin and C#
PPTX
Application Lifecycle Management with TFS
PPTX
architecture of mobile software applications
Bootstrap: the full overview
Building your first iOS app using Xamarin
Building your first android app using Xamarin
MvvmCross Quickstart
DevOps for Your Mobile App
Developing native iOS & Android apps in c# with xamarin
Mobile development strategies with MVVM
Continuous Integration & deployment for your Xamarin app
Cross Platform, Native Mobile Application Development Using Xamarin and C#
Application Lifecycle Management with TFS
architecture of mobile software applications
Ad

Similar to Real world apps with Xamarin and MVVM (20)

PPTX
Cross-platform Apps using Xamarin and MvvmCross - Martijn van Dijk - Codemoti...
PPTX
Xamarin & MvvmCross in depth
PPTX
MVVM frameworks - MvvmCross
PDF
Cross platform mobile development with visual studio and xamarin
PPTX
Hot tuna - from Sean Cross
PPTX
MvvmCross
PPTX
C# everywhere - Building Cross-Platform Apps with Xamarin and MvvmCross
PDF
MvvmCross Seminar
PDF
MvvmCross Introduction
PPTX
C# everywhere - Building Cross-Platform Apps with Xamarin and MvvmCross
PDF
Cross platform Xamarin Apps With MVVM
PPTX
Dia 4 introduction to cross platform mobile development
PPTX
Reaproveitamento de código com Xamarin e MVVM Cross
PDF
Mvvm Pattern in Xamarin - MvvmCross and Xamarin.Forms
PPTX
Dia 4.1 mvvm cross
PPTX
Building Cross Platform Mobile Solutions
PPTX
Building Cross Platform Mobile Solutions
PPTX
Cross platform native mobile app development for iOS, Android and Windows usi...
PPTX
Developing Android and iOS Apps With C#, .NET, Xamarin, Mono, and Windows Azure
PDF
Xamarin: The Future of App Development
Cross-platform Apps using Xamarin and MvvmCross - Martijn van Dijk - Codemoti...
Xamarin & MvvmCross in depth
MVVM frameworks - MvvmCross
Cross platform mobile development with visual studio and xamarin
Hot tuna - from Sean Cross
MvvmCross
C# everywhere - Building Cross-Platform Apps with Xamarin and MvvmCross
MvvmCross Seminar
MvvmCross Introduction
C# everywhere - Building Cross-Platform Apps with Xamarin and MvvmCross
Cross platform Xamarin Apps With MVVM
Dia 4 introduction to cross platform mobile development
Reaproveitamento de código com Xamarin e MVVM Cross
Mvvm Pattern in Xamarin - MvvmCross and Xamarin.Forms
Dia 4.1 mvvm cross
Building Cross Platform Mobile Solutions
Building Cross Platform Mobile Solutions
Cross platform native mobile app development for iOS, Android and Windows usi...
Developing Android and iOS Apps With C#, .NET, Xamarin, Mono, and Windows Azure
Xamarin: The Future of App Development

More from Gill Cleeren (9)

PPTX
Hello windows 10
PPTX
Top 10 HTML5 features every developer should know!
PPTX
Building a community - BuildStuff Lithuania 2014
PPTX
C# everywhere: Xamarin and cross platform development
PPTX
Getting started with jQuery
PPTX
Top 10 HTML5 features
PPTX
Comparing XAML and HTML: FIGHT!
PPTX
Why you shouldn't dismiss windows 8 for your lob apps
PPTX
Advanced MVVM in Windows 8
Hello windows 10
Top 10 HTML5 features every developer should know!
Building a community - BuildStuff Lithuania 2014
C# everywhere: Xamarin and cross platform development
Getting started with jQuery
Top 10 HTML5 features
Comparing XAML and HTML: FIGHT!
Why you shouldn't dismiss windows 8 for your lob apps
Advanced MVVM in Windows 8

Recently uploaded (20)

PDF
Softaken Excel to vCard Converter Software.pdf
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
AI in Product Development-omnex systems
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
Nekopoi APK 2025 free lastest update
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
top salesforce developer skills in 2025.pdf
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
System and Network Administration Chapter 2
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
Softaken Excel to vCard Converter Software.pdf
Operating system designcfffgfgggggggvggggggggg
AI in Product Development-omnex systems
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Design an Analysis of Algorithms II-SECS-1021-03
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Nekopoi APK 2025 free lastest update
VVF-Customer-Presentation2025-Ver1.9.pptx
Odoo Companies in India – Driving Business Transformation.pdf
top salesforce developer skills in 2025.pdf
Odoo POS Development Services by CandidRoot Solutions
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
wealthsignaloriginal-com-DS-text-... (1).pdf
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Reimagine Home Health with the Power of Agentic AI​
PTS Company Brochure 2025 (1).pdf.......
Adobe Illustrator 28.6 Crack My Vision of Vector Design
System and Network Administration Chapter 2
2025 Textile ERP Trends: SAP, Odoo & Oracle

Real world apps with Xamarin and MVVM

Editor's Notes

  • #43: Don’t forget App and AppStart!
  • #57: the native Application will 'be created' first within the construction of the native Application, a Setup will be created the Setup will perform very basic tasks - e.g. initialisation of the IoC system (seehttps://github.com/slodge/MvvmCross/wiki/Service-Location-and-Inversion-of-Control) then the Setup will call into the core project, construct an App and will call Initialize on it. during the Initialize your App will typically: register your app-specific services with the IoC system create and register a Start object the Setup will then configure the UI side of the project - especially things like lookup tables for views finally the Setup will start the MvvmCross binding engine (if needed) with Setup complete, your native Application can then actually start. to do this, it requests a reference to the Start object and calls Start() on it after this, the app will start presenting ViewModels using databound Views
  • #69: the native Application will 'be created' first within the construction of the native Application, a Setup will be created the Setup will perform very basic tasks - e.g. initialisation of the IoC system (seehttps://github.com/slodge/MvvmCross/wiki/Service-Location-and-Inversion-of-Control) then the Setup will call into the core project, construct an App and will call Initialize on it. during the Initialize your App will typically: register your app-specific services with the IoC system create and register a Start object the Setup will then configure the UI side of the project - especially things like lookup tables for views finally the Setup will start the MvvmCross binding engine (if needed) with Setup complete, your native Application can then actually start. to do this, it requests a reference to the Start object and calls Start() on it after this, the app will start presenting ViewModels using databound Views