SlideShare a Scribd company logo
MvvmCross Introduction

    13th December 2012
          @slodge
Presentation Model


Represent the state and behavior of the presentation
   independently of the GUI controls used in the
                      interface.




             http://martinfowler.com/eaaDev/PresentationModel.html
In 2005…

      Model/View/ViewModel is a variation of
Model/View/Controller that is tailored for modern UI
   development platforms where the View is the
  responsibility of a designer rather than a classic
                      developer.


                            Tales from the Smart Client, John Grossman
  http://blogs.msdn.com/b/johngossman/archive/2005/10/08/478683.aspx
Also in 2005…
• 10 years of dev – C++, C, VB, Java, JavaScript,
  LISP, SmallTalk, Delphi, …
• A year off travelling
  – from Argentina to Zambia
• DeveloperDeveloperDeveloper
• 1 conclusion:
MvvmCross Introduction
   Evolving the dinosaur
    13th December 2012
          @slodge
What we’ll cover…
•   MVVM Theory
•   .Net MVVM
•   A practical example – some code!
•   Interface Driven Development
    – Portable Class Libraries
    – Unit Testing
    – Plugins
• Some examples
What we’ll cover…
•   MVVM Theory
•   .Net MVVM
•   A practical example – some code!
•   Interface Driven Development
    – Portable Class Libraries
    – Unit Testing
    – Plugins
• Some examples
M-V-VM
Detailed flow
What we’ll cover…
•   MVVM Theory
•   .Net MVVM
•   A practical example – some code!
•   Interface Driven Development
    – Portable Class Libraries
    – Unit Testing
    – Plugins
• Some examples
ViewModels Public Properties

private bool _isSearching;
public bool IsSearching
{
     get { return _isSearching; }
     set
     {
          _isSearching = value;
          RaisePropertyChanged("IsSearching");
     }
}
For ViewModel Changes

public interface INotifyPropertyChanged
{
     event PropertyChangedEventHandler PropertyChanged;
}


public class PropertyChangedEventArgs : EventArgs
{
     public string PropertyName { get; }
}
For Collections
public interface INotifyCollectionChanged
{
     event NotifyCollectionChangedEventHandler CollectionChanged;
}

public enum NotifyCollectionChangedAction
{
     Add, Remove, Replace, Move, Reset,
}

public class NotifyCollectionChangedEventArgs : EventArg
{
     public NotifyCollectionChangedAction Action { get; }
     public IList NewItems { get; }
     public IList OldItems { get; }
     public int NewStartingIndex { get; }
     public int OldStartingIndex { get; }
}
For Actions


public interface ICommand
{
    event EventHandler CanExecuteChanged;
    bool CanExecute(object parameter);
    void Execute(object parameter);
}
.Net Implementation


     ICommand
  Public Property Set



   INotifyPropertyChanged
  INotifyCollectionChanged
     Public Property Get
Why?
To Enable
• Awesome UI and Data Development
• Unit Testing of code
• Large applications to have a common
  architecture
• Different platforms can share code
What we’ll cover…
•   MVVM Theory
•   .Net MVVM
•   A practical example – some code!
•   Interface Driven Development
    – Portable Class Libraries
    – Unit Testing
    – Plugins
• Some examples
What is MvvmCross?


      Code!
Code evolution I
•   Single Mono for Android Project
•   Good separation of UI from ‘Model’ code
•   Simple – it works
•   But:
    – No testing
    – No testability
    – Portability by cut/paste
Code Evolution 2
• MvvmCross Library switched in
  – PCL code
  – Formal DI/IoC used
• On UI:
  – DataBinding arrived
  – Code got much thinner!
  – XML got bigger
• Not all win:
  – External Dependencies got larger
  – Code overall increased in size
Code Evolution 3
• Cross Platform
• All UIs MVVM
• 100% shared application
  logic
• 100% shared test harness
Data-Binding
WP/WinRT
 99% Xaml




   Droid
Mainly Axml
Some .Dialog




  Touch
Some .Dialog
 Some .XIB
  Some C#
What we’ll cover…
•   MVVM Theory
•   .Net MVVM
•   A practical example – some code!
•   Interface Driven Development
    – Portable Class Libraries
    – Unit Testing
    – Plugins
• Some examples
Portable Class Libraries
Unit Testing
“I get paid for code that works, not for tests, so my
philosophy is to test as little as possible to reach a
given level of confidence.
…
When coding on a team, I modify my strategy to
carefully test code that we, collectively, tend to get
wrong.”
                                                Kent Beck
                http://stackoverflow.com/questions/153234/how-deep-are-your-unit-tests
Plugin – Native abstractions
1. Declare common functionality (an interface)
   public interface IMvxComposeEmailTask
   {
       void ComposeEmail(string to, string cc, string subject, string body, bool isHtml);
   }

2. Write platform specific implementations
  public class MvxComposeEmailTask : MvxWindowsPhoneTask, IMvxComposeEmailTask
  {
       public void ComposeEmail(string to, string cc, string subject, string body, bool isHtml)
       {
           var task = new EmailComposeTask() { To = to, Subject = subject, Cc = cc, Body = body };
           DoWithInvalidOperationProtection(task.Show);
       }
    }

3. In apps, use the interface and not the implementation
   protected void ComposeEmail(string to, string subject, string body)
   {
        Cirrious.MvvmCross.Plugins.Email.PluginLoader.Instance.EnsureLoaded();
        var task = this.GetService<IMvxComposeEmailTask>();
        task.ComposeEmail(to, null, subject, body, false);
   }
Sphero – Plugin Magic
• Plugin Magic

• Each Plugin:
   – 1 PCL
   – 1 Assembly per platform
Why?
To Enable
• Awesome UI and Data Development
• Unit Testing of code
• Large applications to have a common
  architecture
• Different platforms can share code
What we’ll cover…
•   MVVM Theory
•   .Net MVVM
•   A practical example – some code!
•   Interface Driven Development
    – Portable Class Libraries
    – Unit Testing
    – Plugins
• Some examples
MonoCross
A team in a galaxy far far away




@imaji @mrlacey @sichy @slodge @touch4apps …
Redth in Canada




https://github.com/Redth/WshLst/
Rune in Norway




https://github.com/runegri/CrossBox
Jason in UK




http://www.aviva.co.uk/drive/
CheeseBaron in Denmark




http://blog.ostebaronen.dk/
Greg in NYC




http://bit.ly/mvxgshac
JSON.Net Downunder (?)
Olivier in France




http://www.e-naxos.com/UsIndex.html
Dan in Italy




http://bit.ly/mvxDanA
Zoldeper in Hungary?




https://github.com/Zoldeper/Blooor
Daniel in Redmond




http://channel9.msdn.com/Events/Build/2012/3-004
What we’ve covered…
•   MVVM Theory
•   .Net MVVM
•   A practical example – some code!
•   Interface Driven Development
    – Portable Class Libraries
    – Unit Testing
    – Plugins
• Some examples
To join in…
If you want to join in:
   •   Tool up
   •   Share
   •   Reuse
   •   Test
   •   Architect
MS-PL on GitHub




http://github.com/slodge/MvvmCross
Some other talks available




http://bit.ly/mvxTweetPic
C# - 1 Stack - Cloud to Mobile
Data Access

Business Logic

Presentation


Service Consumption         Local Data/Services

Business Logic

UI Logic

WP7                   iOS   Droid                 Win8
Not as cool as dinosaurs
Data Access

Business Logic

Presentation


Service Consumption         Local Data/Services

Business Logic

UI Logic

WP7                   iOS   Droid                 Win8
Some credits
Images from Wikipedia Commons:
•   http://en.wikipedia.org/wiki/File:Macronaria_scrubbed_enh.jpg
•   http://en.wikipedia.org/wiki/File:Human-
    eoraptor_size_comparison%28v2%29.png



Diagrams from Java – ZK
•   http://books.zkoss.org/wiki/ZK_Developer%27s_Reference/MVVM



Sample projects as credited inline
Thanks for listening…
http://cirrious.com

http://slodge.blogspot.com
http://github.com/slodge/mvvmcross

me@slodge.com
@slodge

Stuart Lodge,
I’m a Dinosaur
Xamarin
               Seminar
Please give us your feedback
              http://bit.ly/xamfeedback


Follow us on Twitter
                       @XamarinHQ

13th December 2012

More Related Content

PDF
Groovy & Java
PDF
Groovy Tutorial
PDF
Tech io nodejs_20130531_v0.6
PDF
PHP, Java EE & .NET Comparison
PPTX
PDF
Angular 2 : learn TypeScript already with Angular 1
PDF
Starting from scratch in 2017
PDF
javerosmx-2015-marzo-groovy-java8-comparison
Groovy & Java
Groovy Tutorial
Tech io nodejs_20130531_v0.6
PHP, Java EE & .NET Comparison
Angular 2 : learn TypeScript already with Angular 1
Starting from scratch in 2017
javerosmx-2015-marzo-groovy-java8-comparison

What's hot (7)

PDF
Managing Software Dependencies and the Supply Chain_ MIT EM.S20.pdf
PDF
Containerizing legacy applications
PDF
There is something about JavaScript - Choose Forum 2014
PPTX
Introduction to Java Programming Language
PDF
Exploring French Job Ads, Lynn Cherny
PDF
Behaviour testing for single-page applications and API’s
PPT
.NET Vs J2EE
Managing Software Dependencies and the Supply Chain_ MIT EM.S20.pdf
Containerizing legacy applications
There is something about JavaScript - Choose Forum 2014
Introduction to Java Programming Language
Exploring French Job Ads, Lynn Cherny
Behaviour testing for single-page applications and API’s
.NET Vs J2EE
Ad

Viewers also liked (8)

PDF
18.lifenet benkyo kai
PDF
29.2010 1128 mf_forum
PDF
11.2010 0528 tbli_lip
PPT
Nature Of Sound
PDF
02.his 2011 0305
PDF
17.edu forum
PDF
16.2010 0829 b4_s_seminar
PDF
Forum flyer2012 v2
18.lifenet benkyo kai
29.2010 1128 mf_forum
11.2010 0528 tbli_lip
Nature Of Sound
02.his 2011 0305
17.edu forum
16.2010 0829 b4_s_seminar
Forum flyer2012 v2
Ad

Similar to MvvmCross Introduction (20)

PPTX
Getting started with Xamarin forms
PPTX
MvvmCross
PPTX
Advanced MVVM in Windows 8
PPTX
Mobile development strategies with MVVM
PPTX
MVVM ( Model View ViewModel )
PDF
Cross platform mobile development with visual studio and xamarin
PDF
Portable Class Libraries and MVVM
PPTX
MVVM frameworks - MvvmCross
PPTX
C# everywhere - Building Cross-Platform Apps with Xamarin and MvvmCross
PPTX
Building xamarin.forms apps with prism and mvvm
PPTX
Hot tuna - from Sean Cross
PPTX
C# everywhere - Building Cross-Platform Apps with Xamarin and MvvmCross
PPTX
Applied MVVM in Windows 8 apps: not your typical MVVM session!
PPTX
Adopting MVVM
PDF
Mvvm Pattern in Xamarin - MvvmCross and Xamarin.Forms
PPTX
Training: MVVM Pattern
PDF
XAML Development with Xamarin - Jesse Liberty | FalafelCON 2014
PDF
Cross platform Xamarin Apps With MVVM
PDF
How I Accidentally Discovered MVVM
PDF
Introduction To MVVM
Getting started with Xamarin forms
MvvmCross
Advanced MVVM in Windows 8
Mobile development strategies with MVVM
MVVM ( Model View ViewModel )
Cross platform mobile development with visual studio and xamarin
Portable Class Libraries and MVVM
MVVM frameworks - MvvmCross
C# everywhere - Building Cross-Platform Apps with Xamarin and MvvmCross
Building xamarin.forms apps with prism and mvvm
Hot tuna - from Sean Cross
C# everywhere - Building Cross-Platform Apps with Xamarin and MvvmCross
Applied MVVM in Windows 8 apps: not your typical MVVM session!
Adopting MVVM
Mvvm Pattern in Xamarin - MvvmCross and Xamarin.Forms
Training: MVVM Pattern
XAML Development with Xamarin - Jesse Liberty | FalafelCON 2014
Cross platform Xamarin Apps With MVVM
How I Accidentally Discovered MVVM
Introduction To MVVM

More from Stuart Lodge (17)

PDF
Helping the Lions Roar
PDF
Wpug meeting - wp to win8 experiences
PDF
AlphaLabs - Node Garden with Speech
PDF
About Cirrious ltd
PDF
C# Client to Cloud
PPTX
How to make a pig udf
PDF
C# - Azure, WP7, MonoTouch and Mono for Android (MonoDroid)
PPTX
Mvvm cross – going portable
PPTX
Dev evening - MonoTouch, MonoDroid, Mvvm MvvmCross and databinding
PPTX
Wpug mvvm and data binding
PPTX
Ui testing for Windows Phone
PPTX
Ui Testing on Windows Phone
PPT
How To use Map Blogs
DOC
Uk Nuke Rpx Authentication For Dot Net Nuke
DOC
Uk Nuke Facebook Connect Authentication For Dot Net Nuke
DOC
UkNuke Facebook Connect Authentication For DotNetNuke 5
PPT
10 things I’ve learnt In the clouds
Helping the Lions Roar
Wpug meeting - wp to win8 experiences
AlphaLabs - Node Garden with Speech
About Cirrious ltd
C# Client to Cloud
How to make a pig udf
C# - Azure, WP7, MonoTouch and Mono for Android (MonoDroid)
Mvvm cross – going portable
Dev evening - MonoTouch, MonoDroid, Mvvm MvvmCross and databinding
Wpug mvvm and data binding
Ui testing for Windows Phone
Ui Testing on Windows Phone
How To use Map Blogs
Uk Nuke Rpx Authentication For Dot Net Nuke
Uk Nuke Facebook Connect Authentication For Dot Net Nuke
UkNuke Facebook Connect Authentication For DotNetNuke 5
10 things I’ve learnt In the clouds

Recently uploaded (20)

PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
A Presentation on Artificial Intelligence
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Encapsulation theory and applications.pdf
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
Cloud computing and distributed systems.
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Electronic commerce courselecture one. Pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Building Integrated photovoltaic BIPV_UPV.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
A Presentation on Artificial Intelligence
Encapsulation_ Review paper, used for researhc scholars
Encapsulation theory and applications.pdf
MYSQL Presentation for SQL database connectivity
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Cloud computing and distributed systems.
Understanding_Digital_Forensics_Presentation.pptx
Unlocking AI with Model Context Protocol (MCP)
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Electronic commerce courselecture one. Pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
The Rise and Fall of 3GPP – Time for a Sabbatical?
NewMind AI Monthly Chronicles - July 2025
Reach Out and Touch Someone: Haptics and Empathic Computing
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf

MvvmCross Introduction