Download - MVVM frameworks - MvvmCross
MVVM frameworks - MvvmCrossFlavius-Radu DEMIAN
A bit about me
• General Manager@Deventure
• Timisoara .Net Meetup organizer
• Mobile and Web developer
• Xamarin and Umbraco enthusiast
• In love with technology
[email protected] @flaviusdemian
Agenda
Xamarin’s Unique ApproachWhat is MVVM?Why MVVM?The MvvmCross magic Data-Binding, Commands, NavigationAdvantagesDisadvantages
Expectations
I wish to have an interactive presentation.Please feel free to ask questions any time.
My ultimate goal is to make you
curios.
Go home and try it yourself!
Xamarin’s Unique Approach
Xamarin’s Unique Approach
Xamarin’s Unique Approach
• native user interface• native performance• shared code across platforms• usage of C# & .NET framework• full API coverage• fewer developers
The Xamarin MagicWrite Everything in C#
The Xamarin MagicXamarin 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%.
Xamarin Architecture Guide
What is MVVM?
Model View ViewModel
MVVM Technical DetailsIt is derived from the Model View Controller Pattern.
• properties• data binding• INotifyPropertyChanged• INotifyCollectionChanged• IValueConverter• ICommand• UI thread
Why MVVM?
MVVM Pros and ConsThere 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
The MvvmCross Magic
The MvvmCross Magic
It’s an open-source framework maintained by Stuart Lodge, Martijn van Dijk & 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.
The MvvmCross Magic
The MvvmCross Magic
MvvmCross has support for:• Xamarin.iOS• Mac• Xamarin.Android• Windows Presentation Foundation• Windows Phone• Windows 8• Universal Windows Platform
The MvvmCross MagicIt has huge popularity and the community is very active.
https://jabbr.net/#/rooms/mvvmcrosshttps://xamarinchat.slack.com/messages/mvvmcross/https://github.com/MvvmCross/MvvmCross
Data Binding, Commands, Navigation
Data Binding - Properties
No C#, just XAML
<TextBox Text="{Binding Password, Mode=TwoWay}" />
Data Binding - Properties
No C#, just XML
xmlns:local="http://schemas.android.com/apk/res-auto"<EditText local:MvxBind="Text Password"
Data Binding - Properties
Just C#
var set = this.CreateBindingSet<LoginViewController, LoginViewModel>(); set.Bind(textField_Password).To(vm => vm.Password);
Data Binding - ListviewsNo C#, just XAML
<ListBox ItemsSource="{Binding MyCollection}"<ListBox.ItemTemplate>
<DataTemplate> …..</DataTemplate>
</ListBox.ItemTemplate></ListBox>
Data Binding - Listviews
No C#, just XML
<Mvx.MvxListView local:MvxBind="ItemsSource MyCollection; ItemClick ViewDetailsCommand"local:MvxItemTemplate="@layout/item_template_row" />
Data Binding - Listviews
Just C#
var set = this.CreateBindingSet<XViewController, XViewModel>();set.Bind(source).To(x => x.MyCollection);set.Apply();
ViewModel Commands
No C#, just XAML
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"xmlns:commandbinding="clr-namespace:Cirrious.MvvmCross.WindowsPhone.Commands;assembly=Cirrious.MvvmCross.WindowsPhone" <TextBlock Text="{Binding Name}">
<i:Interaction.Triggers><i:EventTrigger EventName="Tap">
<commandbinding:MvxEventToCommand Command="{Binding MyCommand}" />
</i:EventTrigger></i:Interaction.Triggers>
</TextBlock>
ViewModel Commands
No C#, just XML
xmlns:local="http://schemas.android.com/apk/res-auto"<Button local:MvxBind="Click LoginCommand" />
ViewModel Commands
Just C#
var set = this.CreateBindingSet<LoginViewController, LoginViewModel>();set.Bind(btn_Login).To(x => x.LoginCommand);set.Apply();
Navigation
Go forward:CurrentViewModelInstance.ShowViewModel<NewViewModel>();
Navigation
Go back:CurrentViewModelInstance.Close(this);
MvvmCross App Architecture
App ArchitectureThe project should be split in 2:
Common core which contains:• models• viewmodels• business logic• data access layer
UI-project per platform:• each platform views
Small Demo Time
MvvmCross Pros & Cons
Pros:• interchangeable code module• supports Test Driven Development (TDD)• it follows the Core pattern• it has data binding
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
Thank you very much.