Xamarin.Forms and MVVM by Andres Castro @ Bluetube
-
Upload
robert-echevarria -
Category
Software
-
view
779 -
download
3
Transcript of Xamarin.Forms and MVVM by Andres Castro @ Bluetube
Xamarin.Forms + MVVMAndres Castro
Xamarin Overview
Xamarin Overview
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
• 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?
• 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!
• 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!
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
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
• 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)
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
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
• 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