XamarinFormsNotesForProfessionals.pdf

(2669 KB) Pobierz
Xamarin
.Forms
Xamarin.Forms
Notes for Professionals
Notes for Professionals
of professional hints and tricks
100+ pages
GoalKicker.com
Free Programming Books
Disclaimer
This is an unocial free book created for educational purposes and is
not aliated with ocial Xamarin.Forms group(s) or company(s).
All trademarks and registered trademarks are
the property of their respective owners
Contents
About
................................................................................................................................................................................... 1
Chapter 1: Getting started with Xamarin.Forms
........................................................................................... 2
Section 1.1: Installation (Visual Studio)
......................................................................................................................... 2
Section 1.2: Hello World Xamarin Forms: Visual Studio
............................................................................................. 4
Chapter 2: Why Xamarin Forms and When to use Xamarin Forms
.................................................... 7
Section 2.1: Why Xamarin Forms and When to use Xamarin Forms
....................................................................... 7
Chapter 3: Xamarin Forms Layouts
.................................................................................................................... 8
Section 3.1: AbsoluteLayout
.......................................................................................................................................... 8
Section 3.2: Grid
........................................................................................................................................................... 10
Section 3.3: ContentPresenter
.................................................................................................................................... 11
Section 3.4: ContentView
............................................................................................................................................ 12
Section 3.5: ScrollView
................................................................................................................................................ 13
Section 3.6: Frame
....................................................................................................................................................... 14
Section 3.7: TemplatedView
....................................................................................................................................... 14
Section 3.8: RelativeLayout
........................................................................................................................................ 15
Section 3.9: StackLayout
............................................................................................................................................ 16
Chapter 4: Xamarin Relative Layout
............................................................................................................... 19
Section 4.1: Box after box
........................................................................................................................................... 19
Section 4.2: Page with an simple label on the middle
............................................................................................. 21
Chapter 5: Navigation in Xamarin.Forms
....................................................................................................... 23
Section 5.1: NavigationPage flow with XAML
............................................................................................................ 23
Section 5.2: NavigationPage flow
.............................................................................................................................. 24
Section 5.3: Master Detail Navigation
....................................................................................................................... 25
Section 5.4: Using INavigation from view model
..................................................................................................... 26
Section 5.5: Master Detail Root Page
........................................................................................................................ 28
Section 5.6: Hierarchical navigation with XAML
....................................................................................................... 29
Section 5.7: Modal navigation with XAML
................................................................................................................. 31
Chapter 6: Xamarin.Forms Page
........................................................................................................................ 32
Section 6.1: TabbedPage
............................................................................................................................................ 32
Section 6.2: ContentPage
........................................................................................................................................... 33
Section 6.3: MasterDetailPage
................................................................................................................................... 34
Chapter 7: Xamarin.Forms Cells
......................................................................................................................... 36
Section 7.1: EntryCell
................................................................................................................................................... 36
Section 7.2: SwitchCell
................................................................................................................................................. 36
Section 7.3: TextCell
.................................................................................................................................................... 37
Section 7.4: ImageCell
................................................................................................................................................. 38
Section 7.5: ViewCell
.................................................................................................................................................... 39
Chapter 8: Xamarin.Forms Views
....................................................................................................................... 41
Section 8.1: Button
....................................................................................................................................................... 41
Section 8.2: DatePicker
............................................................................................................................................... 42
Section 8.3: Entry
......................................................................................................................................................... 43
Section 8.4: Editor
........................................................................................................................................................ 43
Section 8.5: Image
....................................................................................................................................................... 44
Section 8.6: Label
........................................................................................................................................................ 45
Chapter 9: Using ListViews
..................................................................................................................................... 47
Section 9.1: Pull to Refresh in XAML and Code behind
............................................................................................ 47
Chapter 10: Display Alert
........................................................................................................................................ 48
Section 10.1: DisplayAlert
............................................................................................................................................ 48
Section 10.2: Alert Example with only one button and action
................................................................................. 49
Chapter 11: Accessing native features with DependencyService
....................................................... 50
Section 11.1: Implementing text-to-speech
................................................................................................................ 50
Section 11.2: Getting Application and Device OS Version Numbers - Android & iOS - PCL
................................. 53
Chapter 12: DependencyService
......................................................................................................................... 55
Section 12.1: Android implementation
........................................................................................................................ 55
Section 12.2: Interface
................................................................................................................................................. 56
Section 12.3: iOS implementation
............................................................................................................................... 56
Section 12.4: Shared code
........................................................................................................................................... 57
Chapter 13: Custom Renderers
............................................................................................................................ 58
Section 13.1: Accessing renderer from a native project
........................................................................................... 58
Section 13.2: Rounded label with a custom renderer for Frame (PCL & iOS parts)
............................................. 58
Section 13.3: Custom renderer for ListView
.............................................................................................................. 59
Section 13.4: Custom Renderer for BoxView
............................................................................................................. 61
Section 13.5: Rounded BoxView with selectable background color
....................................................................... 65
Chapter 14: Caching
.................................................................................................................................................. 68
Section 14.1: Caching using Akavache
....................................................................................................................... 68
Chapter 15: Gestures
................................................................................................................................................. 70
Section 15.1: Make an Image tappable by adding a TapGestureRecognizer
....................................................... 70
Section 15.2: Gesture Event
......................................................................................................................................... 70
Section 15.3: Zoom an Image with the Pinch gesture
.............................................................................................. 78
Section 15.4: Show all of the zoomed Image content with the PanGestureRecognizer
....................................... 78
Section 15.5: Tap Gesture
........................................................................................................................................... 79
Section 15.6: Place a pin where the user touched the screen with MR.Gestures
.................................................. 79
Chapter 16: Data Binding
........................................................................................................................................ 81
Section 16.1: Basic Binding to ViewModel
.................................................................................................................. 81
Chapter 17: Working with Maps
........................................................................................................................... 83
Section 17.1: Adding a map in Xamarin.Forms (Xamarin Studio)
........................................................................... 83
Chapter 18: Custom Fonts in Styles
................................................................................................................... 92
Section 18.1: Accessing custom Fonts in Syles
.......................................................................................................... 92
Chapter 19: Push Notifications
............................................................................................................................. 94
Section 19.1: Push notifications for Android with Azure
........................................................................................... 94
Section 19.2: Push notifications for iOS with Azure
.................................................................................................. 96
Section 19.3: iOS Example
........................................................................................................................................... 99
Chapter 20: Eects
.................................................................................................................................................. 101
Section 20.1: Adding platform specific Eect for an Entry control
...................................................................... 101
Chapter 21: Triggers & Behaviours
.................................................................................................................. 105
Section 21.1: Xamarin Forms Trigger Example
....................................................................................................... 105
Section 21.2: Multi Triggers
....................................................................................................................................... 106
Chapter 22: AppSettings Reader in Xamarin.Forms
.............................................................................. 107
Section 22.1: Reading app.config file in a Xamarin.Forms Xaml project
............................................................. 107
Chapter 23: Creating custom controls
........................................................................................................... 108
Section 23.1: Label with bindable collection of Spans
........................................................................................... 108
Section 23.2: Implementing a CheckBox Control
................................................................................................... 110
Section 23.3: Create an Xamarin Forms custom input control (no native required)
......................................... 116
Section 23.4: Creating a custom Entry control with a MaxLength property
....................................................... 118
Section 23.5: Creating custom Button
..................................................................................................................... 119
Chapter 24: Working with local databases
................................................................................................ 121
Section 24.1: Using SQLite.NET in a Shared Project
............................................................................................... 121
Section 24.2: Working with local databases using xamarin.forms in visual studio 2015
................................... 123
Chapter 25: CarouselView - Pre-release version
..................................................................................... 133
Section 25.1: Import CarouselView
.......................................................................................................................... 133
Section 25.2: Import CarouselView into a XAML Page
.......................................................................................... 133
Chapter 26: Exception handling
........................................................................................................................ 135
Section 26.1: One way to report about exceptions on iOS
.................................................................................... 135
Chapter 27: SQL Database and API in Xamarin Forms.
........................................................................ 137
Section 27.1: Create API using SQL database and implement in Xamarin forms,
.............................................. 137
Chapter 28: Contact Picker - Xamarin Forms (Android and iOS)
.................................................... 138
Section 28.1: contact_picker.cs
................................................................................................................................ 138
Section 28.2: MyPage.cs
........................................................................................................................................... 138
Section 28.3: ChooseContactPicker.cs
.................................................................................................................... 139
Section 28.4: ChooseContactActivity.cs
.................................................................................................................. 139
Section 28.5: MainActivity.cs
.................................................................................................................................... 140
Section 28.6: ChooseContactRenderer.cs
............................................................................................................... 141
Chapter 29: Xamarin Plugin
................................................................................................................................ 144
Section 29.1: Media Plugin
........................................................................................................................................ 144
Section 29.2: Share Plugin
........................................................................................................................................ 146
Section 29.3: ExternalMaps
...................................................................................................................................... 147
Section 29.4: Geolocator Plugin
............................................................................................................................... 148
Section 29.5: Messaging Plugin
............................................................................................................................... 150
Section 29.6: Permissions Plugin
.............................................................................................................................. 151
Chapter 30: OAuth2
................................................................................................................................................. 155
Section 30.1: Authentication by using Plugin
.......................................................................................................... 155
Chapter 31: MessagingCenter
............................................................................................................................. 157
Section 31.1: Simple example
.................................................................................................................................... 157
Section 31.2: Passing arguments
............................................................................................................................. 157
Section 31.3: Unsubscribing
...................................................................................................................................... 158
Chapter 32: Generic Xamarin.Forms app lifecycle? Platform-dependant!
................................ 159
Section 32.1: Xamarin.Forms lifecycle is not the actual app lifecycle but a cross-platform representation of
it
.......................................................................................................................................................................... 159
Chapter 33: Platform-specific behaviour
..................................................................................................... 161
Section 33.1: Removing icon in navigation header in Anroid
................................................................................ 161
Section 33.2: Make label's font size smaller in iOS
................................................................................................ 161
Chapter 34: Platform specific visual adjustments
.................................................................................. 163
Section 34.1: Idiom adjustments
............................................................................................................................... 163
Section 34.2: Platform adjustments
........................................................................................................................ 163
Section 34.3: Using styles
......................................................................................................................................... 164
Section 34.4: Using custom views
............................................................................................................................ 164
Chapter 35: Dependency Services
................................................................................................................... 165
Section 35.1: Access Camera and Gallery
............................................................................................................... 165
Chapter 36: Unit Testing
....................................................................................................................................... 166
Section 36.1: Testing the view models
..................................................................................................................... 166
Chapter 37: BDD Unit Testing in Xamarin.Forms
..................................................................................... 172
Section 37.1: Simple Specflow to test commands and navigation with NUnit Test Runner
.............................. 172
Section 37.2: Advanced Usage for MVVM
.............................................................................................................. 174
Credits
............................................................................................................................................................................ 175
You may also like
...................................................................................................................................................... 176
Zgłoś jeśli naruszono regulamin