Xamarin & MvvmCross
in depth
Nicolas Milcoff (aka @nmilcoff)
Microsoft MVP - MvvmCross Maintainer
Agenda
▣ MVVM pattern recap
▣ Why to use an Open Source MVVM framework?
▣ MvvmCross
▣ Framework goodies
▣ Demos
▣ Q & A
The MVVM Pattern
MVVM benefits
▣ Highly decoupled components
▣ Code sharing ++
▣ Scalability
▣ Working in parallel made easy
▣ Stable and proven pattern
Open Source (MVVM) Frameworks
▣ Abstractions discussions --
▣ Barriers for new developers --
▣ Requirements focus ++
▣ Time saving ++
▣ Inputs from multiple developers / teams ++
App development
without compromise
MvvmCross
Supported Platforms
▣ Xamarin.Android, Xamarin.iOS
▣ Xamarin.Mac, Xamarin.tvOS
▣ UWP, WPF
▣ Tizen (WIP)
▣ Console!
▣ Xamarin.Forms
Features in a nutshell
▣ ViewModel first Navigation
▣ Data Bindings, Commands and Converters
▣ IoC Container / DI engine
▣ Platform specific widgets
▣ Unit Test Helpers
▣ Plugins
▣ Complete flexibility!
ViewModels
▣ Implement INotifyPropertyChanged
▣ Lifecycle:
□ void Prepare(MyObject parameter)
□ Task Initialize()
□ void Appearing(), void Appeared()
□ void Dissapearing(), void Dissapeared()
□ void ViewDestroyed()
□ void SaveStateToBundle(IMvxBundle bundle)
□ void ReloadFromBundle(IMvxBundle bundle)
Navigation in MvvmCross
Navigation in MvvmCross
▣ All logic remains in the shared code
▣ ViewPresenters for each platform
▣ Presentation attributes for declaration
▣ Presentation Hints for behavior
▣ 100% customizable
Navigation in MvvmCross
public class RootViewModel : MvxViewModel
{
private readonly IMvxNavigationService _navigationService;
public RootViewModel(IMvxNavigationService navigationService)
{
_navigationService = navigationService;
}
private async Task OpenModalAsync()
{
await _navigationService.Navigate<ModalViewModel>();
}
}
Navigation in MvvmCross
[MvxContentPagePresentation(WrapInNavigationPage = true)]
public partial class RootPage : MvxContentPage<RootViewModel>
{
// your code
}
[MvxModalPresentation]
public partial class ModalPage :
MvxContentPage<ModalViewModel>
{
// your code
}
DEMO!
Navigation & ViewPresenters
Data Bindings in MvvmCross
▣ Support for .cs, .xml, .axml, .xaml
▣ Value Converters
▣ Value Combiners
▣ OneWay, TwoWay, OneWayToSource, OneTime
▣ Multiple syntaxes
▣ Support for custom bindings
Data Bindings in MvvmCross
▣ Bindings in .axml (Tibet):
local:mvxBind=“Text MyTextProperty”
local:mvxBind=“Click MyAwesomeCommand”
local:mvxBind=“Checked Inverse(Prop), Mode=TwoWay,
Fallback=False”
Data Bindings in MvvmCross
▣ Bindings in xaml (Tibet):
mvx:Bi.nd="Text MyTextProperty”
mvx:Bi.nd=“Click MyAwesomeCommand”
mvx:Bi.nd=“Checked Inverse(Prop), Mode=TwoWay,
Fallback=False”
Data Bindings in MvvmCross
▣ Bindings in .cs (Fluent):
set.Bind(MyLabel).For(v => v.Text).To(vm => vm.MyProperty);
set.Bind(MyButton).To(vm => vm.MyAwesomeCommand);
set.Bind(MySwitch)
.For(v => v.On)
.To(vm => vm.Prop)
.WithConversion<InverseConverter>()
.WithFallback(false);
DEMO!
Data Binding
IoC Container and DI engine
▣ It’s optional
▣ Service Locator / IoC
▣ Constructor and Property Dependency Injection
▣ Singletons, dynamics, Open Generics, Child
Containers
▣ Bulk registrations
▣ What if I prefer to use $Lib$ instead? Also possible!
IoC Container and DI engine
Source: https://xamarinhelp.com/ioc-container-performance/
DEMO!
IoC Container / DI Engine
Platform specifics
▣ Support for Android.Support packages
▣ Polymorphic lists made easy
▣ Support for background services / push
notifications
▣ iOS Side Menu
▣ Abstraction plugins for most common features
Plugins
▣ Small code pieces that resolve specific situations
▣ Install from NuGet -> Run
▣ Official Plugins: Accelerometer, Visibility, Json,
Color, Localization, Messenger, Email, …
▣ Loads of 3rd party plugins
DEMO!
Plugins
Resources & Documentation
mvvmcross.com
Where our official
documentation lives
github.com/MvvmCross
Official samples and
source code
Slack
xamarinchat.herokuapp.
com. Then join
#mvvmcross
StackOverflow
Ask using the
#mvvmcross tag
Xamarin Forums
Use the official forums
Twitter
Follow and don’t
hesitate to contact
influencers
Get involved!
Support us on
OpenCollective
Contribute on
GitHub
Blog about your
experiences
Use the framework
in your apps
Questions?
Thanks!
Nico Milcoff
@nmilcoff
nicolas.milcoff@d-genix.com

Xamarin & MvvmCross in depth

  • 1.
    Xamarin & MvvmCross indepth Nicolas Milcoff (aka @nmilcoff) Microsoft MVP - MvvmCross Maintainer
  • 2.
    Agenda ▣ MVVM patternrecap ▣ Why to use an Open Source MVVM framework? ▣ MvvmCross ▣ Framework goodies ▣ Demos ▣ Q & A
  • 3.
  • 4.
    MVVM benefits ▣ Highlydecoupled components ▣ Code sharing ++ ▣ Scalability ▣ Working in parallel made easy ▣ Stable and proven pattern
  • 5.
    Open Source (MVVM)Frameworks ▣ Abstractions discussions -- ▣ Barriers for new developers -- ▣ Requirements focus ++ ▣ Time saving ++ ▣ Inputs from multiple developers / teams ++
  • 6.
  • 7.
  • 8.
    Supported Platforms ▣ Xamarin.Android,Xamarin.iOS ▣ Xamarin.Mac, Xamarin.tvOS ▣ UWP, WPF ▣ Tizen (WIP) ▣ Console! ▣ Xamarin.Forms
  • 9.
    Features in anutshell ▣ ViewModel first Navigation ▣ Data Bindings, Commands and Converters ▣ IoC Container / DI engine ▣ Platform specific widgets ▣ Unit Test Helpers ▣ Plugins ▣ Complete flexibility!
  • 10.
    ViewModels ▣ Implement INotifyPropertyChanged ▣Lifecycle: □ void Prepare(MyObject parameter) □ Task Initialize() □ void Appearing(), void Appeared() □ void Dissapearing(), void Dissapeared() □ void ViewDestroyed() □ void SaveStateToBundle(IMvxBundle bundle) □ void ReloadFromBundle(IMvxBundle bundle)
  • 11.
  • 12.
    Navigation in MvvmCross ▣All logic remains in the shared code ▣ ViewPresenters for each platform ▣ Presentation attributes for declaration ▣ Presentation Hints for behavior ▣ 100% customizable
  • 13.
    Navigation in MvvmCross publicclass RootViewModel : MvxViewModel { private readonly IMvxNavigationService _navigationService; public RootViewModel(IMvxNavigationService navigationService) { _navigationService = navigationService; } private async Task OpenModalAsync() { await _navigationService.Navigate<ModalViewModel>(); } }
  • 14.
    Navigation in MvvmCross [MvxContentPagePresentation(WrapInNavigationPage= true)] public partial class RootPage : MvxContentPage<RootViewModel> { // your code } [MvxModalPresentation] public partial class ModalPage : MvxContentPage<ModalViewModel> { // your code }
  • 15.
  • 16.
    Data Bindings inMvvmCross ▣ Support for .cs, .xml, .axml, .xaml ▣ Value Converters ▣ Value Combiners ▣ OneWay, TwoWay, OneWayToSource, OneTime ▣ Multiple syntaxes ▣ Support for custom bindings
  • 17.
    Data Bindings inMvvmCross ▣ Bindings in .axml (Tibet): local:mvxBind=“Text MyTextProperty” local:mvxBind=“Click MyAwesomeCommand” local:mvxBind=“Checked Inverse(Prop), Mode=TwoWay, Fallback=False”
  • 18.
    Data Bindings inMvvmCross ▣ Bindings in xaml (Tibet): mvx:Bi.nd="Text MyTextProperty” mvx:Bi.nd=“Click MyAwesomeCommand” mvx:Bi.nd=“Checked Inverse(Prop), Mode=TwoWay, Fallback=False”
  • 19.
    Data Bindings inMvvmCross ▣ Bindings in .cs (Fluent): set.Bind(MyLabel).For(v => v.Text).To(vm => vm.MyProperty); set.Bind(MyButton).To(vm => vm.MyAwesomeCommand); set.Bind(MySwitch) .For(v => v.On) .To(vm => vm.Prop) .WithConversion<InverseConverter>() .WithFallback(false);
  • 20.
  • 21.
    IoC Container andDI engine ▣ It’s optional ▣ Service Locator / IoC ▣ Constructor and Property Dependency Injection ▣ Singletons, dynamics, Open Generics, Child Containers ▣ Bulk registrations ▣ What if I prefer to use $Lib$ instead? Also possible!
  • 22.
    IoC Container andDI engine Source: https://xamarinhelp.com/ioc-container-performance/
  • 23.
  • 24.
    Platform specifics ▣ Supportfor Android.Support packages ▣ Polymorphic lists made easy ▣ Support for background services / push notifications ▣ iOS Side Menu ▣ Abstraction plugins for most common features
  • 25.
    Plugins ▣ Small codepieces that resolve specific situations ▣ Install from NuGet -> Run ▣ Official Plugins: Accelerometer, Visibility, Json, Color, Localization, Messenger, Email, … ▣ Loads of 3rd party plugins
  • 26.
  • 27.
    Resources & Documentation mvvmcross.com Whereour official documentation lives github.com/MvvmCross Official samples and source code Slack xamarinchat.herokuapp. com. Then join #mvvmcross StackOverflow Ask using the #mvvmcross tag Xamarin Forums Use the official forums Twitter Follow and don’t hesitate to contact influencers
  • 28.
    Get involved! Support uson OpenCollective Contribute on GitHub Blog about your experiences Use the framework in your apps
  • 29.
  • 30.