xamarin.forms and mvvm by andres castro @ bluetube

13
Xamarin.Forms + MVVM Andres Castro

Upload: robert-echevarria

Post on 26-Jan-2017

777 views

Category:

Software


3 download

TRANSCRIPT

Page 1: Xamarin.Forms and MVVM by Andres Castro @ Bluetube

Xamarin.Forms + MVVMAndres Castro

Page 2: Xamarin.Forms and MVVM by Andres Castro @ Bluetube

Xamarin Overview

Page 3: Xamarin.Forms and MVVM by Andres Castro @ Bluetube

Xamarin Overview

Page 4: Xamarin.Forms and MVVM by Andres Castro @ Bluetube

Model–view–controller (MVC)

● The model represents the domain data and business logic.

● The view displays the model.● The controller receives user input and

updates the model.

MVC VS MVVM?

Model-View-ViewModel (MVVM)

● The model represents the domain data (DTO, POCO, etc…)

● The view model is an abstract representation of the view.

● The view displays the view model and sends user input to the view model.

© 2015 Bluetube, LLC

Page 5: Xamarin.Forms and MVVM by Andres Castro @ Bluetube

• Developers and Designers can work “asynchronously”• Easily unit test your ViewModels• Redesign the view without changing any of the code (Android and iOS)• UI refreshes updates handle itself• No central “control” of logic, each view can be independent

© 2015 Bluetube, LLC

So why MVVM?

Page 6: Xamarin.Forms and MVVM by Andres Castro @ Bluetube

• Used to Execute a method when an action is performed, such as a button click• Ability to pass parameter• Ability to have CanExecute

© 2015 Bluetube, LLC

Commands!

Page 7: Xamarin.Forms and MVVM by Andres Castro @ Bluetube

• Implementor fires a PropertyChanged event whenever one of their properties change.

• The data binding mechanism in Xamarin.Forms attaches a handler to this PropertyChanged event so it can be notified when a property changes and keep the target updated with the new value.

© 2015 Bluetube, LLC

View Models And INotifyPropertyChanged!

Page 8: Xamarin.Forms and MVVM by Andres Castro @ Bluetube

Model–view–controller (MVC)

● The model represents the domain data and business logic.

● The view displays the model.● The controller receives user input and updates

the model.

MVC VS MVVM?

© 2015 Bluetube, LLC | [Client Name] Proposal

Model-View-ViewModel (MVVM)

● The model represents the domain data (DTO, POCO, etc…)

● The view model is an abstract representation of the view.

● The view displays the view model and sends user input to the view model.

Lets Look At Some Code

© 2015 Bluetube, LLC

Page 9: Xamarin.Forms and MVVM by Andres Castro @ Bluetube

Model–view–controller (MVC)

● The model represents the domain data and business logic.

● The view displays the model.● The controller receives user input and updates

the model.

MVC VS MVVM?

© 2015 Bluetube, LLC | [Client Name] Proposal

Model-View-ViewModel (MVVM)

● The model represents the domain data (DTO, POCO, etc…)

● The view model is an abstract representation of the view.

● The view displays the view model and sends user input to the view model.

Let’s Compare MVVM and MVC in Code

© 2015 Bluetube, LLC

Page 10: Xamarin.Forms and MVVM by Andres Castro @ Bluetube

• MVVM Light is a lightweight MVVM framework

• Key Features Include:- An ICommand Implementation- Event Bus for sending messages- Simpleloc for Inversion of Control- An INotifyPropertyChanged Implementation (View Model Base)

© 2015 Bluetube, LLC

Recommendation (MvvmLight)

Page 11: Xamarin.Forms and MVVM by Andres Castro @ Bluetube

Model–view–controller (MVC)

● The model represents the domain data and business logic.

● The view displays the model.● The controller receives user input and updates

the model.

MVC VS MVVM?

© 2015 Bluetube, LLC | [Client Name] Proposal

Model-View-ViewModel (MVVM)

● The model represents the domain data (DTO, POCO, etc…)

● The view model is an abstract representation of the view.

● The view displays the view model and sends user input to the view model.

Let’s Look at a MVVMLight Implementation

© 2015 Bluetube, LLC

Page 12: Xamarin.Forms and MVVM by Andres Castro @ Bluetube

Model–view–controller (MVC)

● The model represents the domain data and business logic.

● The view displays the model.● The controller receives user input and updates

the model.

MVC VS MVVM?

© 2015 Bluetube, LLC | [Client Name] Proposal

Model-View-ViewModel (MVVM)

● The model represents the domain data (DTO, POCO, etc…)

● The view model is an abstract representation of the view.

● The view displays the view model and sends user input to the view model.

Questions?

© 2015 Bluetube, LLC

Page 13: Xamarin.Forms and MVVM by Andres Castro @ Bluetube

• https://msdn.microsoft.com/en-us/magazine/dn463786.aspx (MSDN)• https://msdn.microsoft.com/en-us/library/hh848246.aspx (MSDN)• http://galasoft.ch/presentations/presentationDetails.cshtml?name=2015003

(Galasoft)• https://xamarin.com• https://github.com/acastr7/CheapSharkMobile

© 2015 Bluetube, LLC

Sources