The document discusses building cross-platform apps with Xamarin and MvvmCross. Xamarin allows writing code once in C# that can target iOS, Android and Windows platforms. It works by compiling C# to native code for each platform, allowing full access to native APIs and good performance. MvvmCross is an MVVM framework that works with Xamarin to enable code sharing through shared view models and data binding across platforms. It handles navigation and communicating with views. The document outlines the architectures of Xamarin and MvvmCross, and their advantages like testability and code reuse but also disadvantages like additional complexity.
2. A bit about me
• General Manager@Deventure
• Timisoara .Net Meetup organizer
• Mobile and Web developer
• Xamarin and Umbraco enthusiast
• In love with technology
flavius.demian@deventure.co @flaviusdemian
4. Agenda
What is MVVM?
Why MVVM?
The MvvmCross magic
Data-Binding, Commands, Navigation
Advantages
Disadvantages
5. Expectations
I wish to have an interactive presentation.
Please feel free to ask questions any time.
After this presentation, you should know:
• what Xamarin is and how to use it
• the advantages and disadvantages of Xamarin
• what is MVVM
• what Mvvmcross is and how to use it
9. Silo Approach
• each platform with it’s own stack – in it’s own silo
• no code sharing
• multiple teams => many developers
• multiple codebase => synchronization problem
• different toolsets
11. Web Approach
“Write once, run anywhere”.
• no apps to deploy to the stores
• shared codebase
• basically a native app with a Webview
• native look is simulated with CSS
• most times you can tell it is written in HTML
• fewer developers
22. The Xamarin Magic
Xamarin takes the C# code and it compiles it down to native on iOS
and Android.
The magic is that you can also use it on the Windows platform.
(Almost) everything you can do in Objective-C, Swift or Java can be
also done in C# with Xamarin.
Check the limitations on www.xamarin.com .
Since you use C# on all the platforms, code reuse varies from 60% to
90%.
25. iOS Build + Execution Model
• code runs as 100% native app
• full Ahead of Time (AOT)
compilation to produce an ARM
binary for Apple’s App Store
• Mono Framework included
• exposes CocoaTouch SDK
26. iOS Build + Execution Model
We can take advantage of the APIs
exposed by Mono besides the fully
covered iOS APIs.
Since we have Mono involved, we
can use Portable Class Libraries
(PCLs).
30. Always Up-to-Date
Xamarin.iOS offered same-day support for :
iOS 5 / iOS 6 / iOS 7 / iOS 7.1 / iOS 8 / iOS 9
Xamarin offers full support for:
• Google Glass
• Android Wear
• Amazon Fire TV
• Apple Watch and more
35. Code Sharing Techniques
There are multiple ways in which you can share code:
• portable class libraries (PCLs)
• partial classes
• compiler conditional blocks
• shared projects
42. MVVM Technical Details
It is derived from the Model View Controller Pattern.
• properties
• data binding
• INotifyPropertyChanged
• INotifyCollectionChanged
• IValueConverter
• ICommand
• UI thread
44. MVVM Pros and Cons
There is a reason why it’s called a pattern.
Pros:
• separation of concerns
• decoupling
• code reuse
• testability
Cons:
• MVVM is "overkill" for simple UI operations
46. The MvvmCross Magic
It’s an open-source framework maintained by Stuart Lodge & Co.
It has Dependency Injection built-in -> Interface Driven Design.
It has a lot of plugins already written such as location, emails, gallery,
network, SQLite, secure storage, phone calls etc.
#IF plugins -> less work for the developer, but also less control.
48. The MvvmCross Magic
MvvmCross has support for:
• Xamarin.iOS
• Mac
• Xamarin.Android
• Windows Presentation Foundation
• Windows Phone
• Windows 8
• Universal Windows Platform
49. The MvvmCross Magic
It has huge popularity and the community is very active.
https://jabbr.net/#/rooms/mvvmcross
https://xamarinchat.slack.com/messages/mvvmcross/
https://github.com/MvvmCross/MvvmCross
51. Data Binding - Properties
No C#, just XAML
<TextBox Text="{Binding Password, Mode=TwoWay}" />
52. Data Binding - Properties
No C#, just XML
xmlns:local="http://schemas.android.com/apk/res-auto"
<EditText local:MvxBind="Text Password"
53. Data Binding - Properties
Just C#
var set = this.CreateBindingSet<LoginViewController, LoginViewModel>();
set.Bind(textField_Password).To(vm => vm.Password);
54. Data Binding - Listviews
No C#, just XAML
<ListBox
ItemsSource="{Binding MyCollection}"
<ListBox.ItemTemplate>
<DataTemplate> …..
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
55. Data Binding - Listviews
No C#, just XML
<Mvx.MvxListView local:MvxBind="ItemsSource MyCollection;
ItemClick ViewDetailsCommand"
local:MvxItemTemplate="@layout/item_template_row" />
56. Data Binding - Listviews
Just C#
var set = this.CreateBindingSet<XViewController, XViewModel>();
set.Bind(source).To(x => x.MyCollection);
set.Apply();
58. ViewModel Commands
No C#, just XML
xmlns:local="http://schemas.android.com/apk/res-auto"
<Button local:MvxBind="Click LoginCommand" />
59. ViewModel Commands
Just C#
var set = this.CreateBindingSet<LoginViewController, LoginViewModel>();
set.Bind(btn_Login).To(x => x.LoginCommand);
set.Apply();
63. App Architecture
The project should be split in 2:
Common core which contains:
• models
• viewmodels
• business logic
• data access layer
UI-project per platform:
• each platform views
65. MvvmCross Pros & Cons
Pros:
• interchangeable code module
• supports Test Driven Development (TDD)
• it follows the Core pattern
• it has data binding
66. MvvmCross Pros & Cons
Cons:
• it is a non-native pattern for iOS -MVC- and Android -aprox MVC-
• core 3rd party dependency
• lot’s of glue code for custom bindings
67. Xamarin Pros & Cons
Pros:
• native experience
• you can use a lot of components that .NET developers already use
• shared code base
• only one programming language
68. Xamarin Pros & Cons
Cons:
• you need a Mac
• it has a license fee per developer, per platform -> $
• bugs can appear: https://bugzilla.xamarin.com/
• C# is needed