This document provides an overview of Prism Forms Template, an app development framework that uses Prism and Xamarin Forms. It discusses the architecture of the app, which follows an MVVM pattern with separation of the user interface, business logic, and data persistence layers. It also summarizes key components like dependency injection, data services, messaging, localization, and custom controls. Code samples are provided to illustrate concepts like view models, binding, navigation, and list views.
2. INTRODUCTION
• This is what I use.
• iOS and Android
• Xamarin Forms
• Prism
• You will get these slides and the repo.
3. THE APP …
• List of Widgets
• Widget
• Id, Name, Description, Type (enum),
• create/update userId and timestamp
• Pages:
• Tab pages
• List of Widgets
• Display a Widget
• About page
4. ARCHITECTURE …
• Prism:
• Forms does a lot of MVVM and Prism fills in the blanks and makes a few
things easier.
• Xamarin Evolve 2016: MVVM Made Simple with Xamarin.Forms and Prism –
Brian Lagunas: https://www.youtube.com/watch?v=DYRLcqG2BAY
• https://github.com/qmatteoq/XamarinForms-Prism
• MVVM
• Model, View, ViewModel - the names of the folders
• Prism
• Autowire WidgetPage.xaml line 5
• INavigateAware WidgetPageViewModel line 161, WidgetListPageViewModel line
106
• Binding
• WidgetPage.xaml line 76
• Binds “Name” to ViewModel line line 66, Command line 129
5. THREE TIER ARCHITECTURE …
• A three tier architecture is the separation of:
• User Interface Views
• Business Logic ViewModel, Model
• Data persistence Database
• Model – logical model (Widget.cs)
• Database / Dto – physical model (WidgetDto.cs)
• Both inherit from a base (see UpdatedTimestamp in BaseModel.cs)
• ModelControllers to handle model wide functions (rather than using statics
methods)
• WidgetDto
• This is a simple app – the value is hard to see.
• In more complex the Dto may bring complex structure from the server like children
records.
• Efficiency is in the Dto’s, Logic is in the models.
6. GENERAL CODE COMPONENTS …
• Dependency injection
• WidgetListPageViewModel line 29
• Service Locator
• BaseModel.cs line 45
• SQLite
• IDataService implemented by DataService
• View models do not call database services or you will break 3 tier principles.
• Object Disposal
• Line 114 of Widget.cs
• Hockey App
• Crash reporting: Settings.cs line 13
• Event reporting: App.xaml.cs -> OnSleep, OnStart, OnResume Line 78
7. GENERAL CODE COMPONENTS …
• Batch timer (e.g. for polling server)
• Line 85 of App.xaml.cs
• Message Bus (e.g. notifying a list view to refresh itself when
server changes)
• Subscribe: WidgetListPageViewModel line 39, 47
• Send: WidgetRowViewModel line 151
• Multi-Language
• Resources / AppResources.resx Default English
• Resources / AppResources.es.resx Spanish
• in XAML: WidgetPage.xaml line 59
8. LIST VIEWS …
• Row as a ViewModel
• E.g. Setting source as an ObservableCollection doesn’t let you put
buttons on a row.
• WidgetListPage line 17 ItemSource = WidgetVM
• WidgetListPageViewModel line 71
• ObservableColection< WidgetRowViewModel >
• Loading them line 138
• WidgetRow.xaml line 55 has the “Sell” button
• On Item Tapped line 102 of List view model
• Pull to refresh line 19, 20, 21 of WidgetListPage.xaml
• Swipe to delete line 13 of WidgetRow.xaml
9. XAML …
• Grid WidgetRow.xaml line 17
• Converters WidgetPage.xaml lines 7, 21, 112
• CustomControl
• Defined: CustomControl/CustomSwitch
• Implemented: iOS and Droid: CustomControl/CustomerSwitchRenderer
• Styles
• ’Variables’ App.xaml line 14 onwards
• Implicit: App.xaml line 57
• Custom: App.xaml line 128
• Used: WidgetRow.xaml line 39