SlideShare une entreprise Scribd logo
1  sur  89
https://goo.gl/Pg7x9q
Xamarin.Forms a different
approach to cross-platform
native mobile development
https://goo.gl/Pg7x9q
1. Create asingle screen cross-
platform application
2. Arrange the UIusing Layouts
3. Useplatform-specific features in
shared code
Objectives
Create a single screen
cross-platform application
❖ Traditional vs. Xamarin.Forms
❖ Xamarin.Forms project structure
❖ Application Components
❖ "Hello, Forms!"
Tasks
❖ Traditional Xamarin approach allows for shared business logic and non-
sharable platform-specific code for the UI layer
Xamarin.iOS and Xamarin.Android
iOS
C# UI
Window
s C#
UI
Android
C# UI
Shared C# business logic
Xamarin.iOS and Xamarin.Android
❖ Xamarin.Forms allows you to describe the UIonce using ashared set of
elements which create a native UIat runtime
Xamarin.Forms
iOS
C# UI
Window
s C#
UI
Android
C# UI
Shared C# business logic
Shared C# UI
Shared C# business logic
Xamarin.iOS and Xamarin.Android Xamarin.Forms
❖ Xamarin.Forms isa cross-
platform UIframework to
create mobile apps for:
▪ Android 4.0+
▪ iOS 8.0+
▪ Windows 10
What is Xamarin.Forms?
Flexible
Layout
Standard
Controls
Custom
Controls
Data
Binding
Engine
XAML
Navigation
Styles +
Triggers
Maps
Xamarin.Forms platform support
Shared C# UI
Shared C# logic
❖ Xamarin.Forms supports abroad selection of mobile and desktop
platforms and UI frameworks
iOS mac
❖ Visual Studio for Windows includes built-in project templates for
Xamarin.Forms applications
Creating a Xamarin.Forms App [Windows]
Available under
Cross-Platform
❖ Visual Studio for Mac includes built-in project templates for
Xamarin.Forms applications
Creating a Xamarin.Forms App [Mac]
After selecting
your template,
a project wizard
walks through
the available
options
Project Structure
❖ The Xamarin CrossPlatform App project template creates several
related projects
Platform-specific
projects act as
"host" to create
native application
PCLor SAPused
to hold shared
code that defines
UIand logic
❖ Most of your code will go into the PCLused for shared logic + UI
Project Structure - PCL
Default template creates
anApp classwhich
decides the initial screen
for the application
❖ Platform-specific projects usethe
shared code (PCLor SAP),but not
the other way around
❖ Xamarin.Forms defines the UIand
behavior in the PCLor SAP(shared)
and then calls it from each
platform-specific project
Project Structure - Dependencies
Shared
Code
iOS
project
Android
project
Windows
project
❖ Should update Xamarin.Forms Nuget package when starting anew project
Xamarin.Forms updates [Windows]
❖ Should update Xamarin.Forms Nuget package when starting anew project
Xamarin.Forms updates [Mac]
Creating aXamarin.Forms application
Demonstration
❖ Xamarin.Forms applications have two required components which are
provided by the template
Xamarin.Forms app anatomy
Application Page(s)
Provides initialization for
the application
Represents a single
screen to display
Xamarin.Forms Application
❖ Applicationclassprovides a
singleton which manages:
▪ Lifecycle methods
▪ Modal navigation notifications
▪ Currently displayed page
▪ Application state persistence
❖ New projects will have a derived
implementation named App
Note: Windows apps also have an Application class,make sure not to confuse them!
❖ Application classprovides lifecycle methods which can be
used to manage persistence and refresh your data
Xamarin.Forms Application
public classApp :Application
{ ...
protected override void OnStart() {} protected
override void OnSleep() {} protected override void
OnResume() {}
}
UseOnStart to initialize
and/or reload your app's data
UseOnSleep tosavechanges
or persist information
UseOnResumeto refresh
your displayed data
❖ Application classalso includes astring object
property bag which ispersisted between app launches
Persisting information
// Save off username in globalpropertybag
Application.Current.Properties["username"] = username.Text;
// Restore the username before it is displayed
if (Application.Current.Properties.ContainsKey("username")) {
var uname =Application.Current.Properties["username"]as string
?? "";
username.Text= uname;
}
❖ Application UIisdefined in terms of pagesandviews
Creating the application UI
Pagerepresents a single
screen displayed in the app
OK
Name:Views are the UI
controls the user
interacts with
Pages
Content
❖ Page isan abstract classused to define a single screenof content
▪ derived types provide specific visualization / behavior
Displays a single
piece of content
(visual thing)
❖ Page isan abstract classused to define a single screenof content
▪ derived types provide specific visualization / behavior
Pages
Content Master Detail
Manages two
panes of
information
❖ Page isan abstract classused to define a single screenof content
▪ derived types provide specific visualization / behavior
Pages
Content Master Detail Navigation
Manages a stack
of pages with
navigation bar
❖ Page isan abstract classused to define a single screenof content
▪ derived types provide specific visualization / behavior
Pages
Content Master Detail Navigation Tabbed
Pagethat
navigates
between children
using tab bar
Adding a new ContentPage to aXamarin.Forms application
Demonstration
❖ View isthe base classfor all visual controls, most
standard controls are present
Views
Label Image SearchBar
Entry ProgressBar ActivityIndicator
Button Slider OpenGLView
Editor Stepper WebView
DatePicker Switch ListView
BoxView TimePicker
Frame Picker
❖ Button provides aclickable surface withtext
Views - Button
OK
var okButton = new Button() { Text =
"OK"
};
okButton.Clicked+= OnClick;
void OnClick(object sender, EventArgs e) {
...
}
Views - Label
❖ UseaLabel to display read-only textblocks
Hello, Forms!
var hello = new Label() { Text =
"Hello,Forms!",
HorizontalTextAlignment= TextAlignment.Center, TextColor =
Color.Blue,
FontFamily = "Arial"
};
❖ Usean Entry control if you want the user to provide input with an on-
screen or hardware keyboard
Views - Entry
Hello
var edit = new Entry() { Keyboard =
Keyboard.Text, PlaceholderText= "Enter
Text"
};
❖ Platform defines arenderer for each view that turns each view into the
appropriate platform-specific control
Rendering views
var button= new Button{
Text = "ClickMe!"
};
UIdefined using a Xamarin.Forms Button
Android.Widget.Button
UIKit.UIButton
Windows.UI.Xaml.Controls.Button
Visual adjustments
❖ Views utilize properties to adjust visual appearance and behavior
var numEntry = new Entry { Placeholder =
"Enter Number", Keyboard =
Keyboard.Numeric
};
var callButton = new Button { Text = "Call",
BackgroundColor = Color.Blue,
TextColor = Color.White
};
❖ Controls useevents to provide interaction behavior, should be very
familiar model for most .NET developers
Providing Behavior
var numEntry = new Entry { ... };
numEntry.TextChanged += OnTextChanged;
...
void OnTextChanged (object sender, string newValue)
{
...
}
Youcan usetraditional delegates, anonymous methods, or lambdas to handle events
Creating our first Xamarin.Forms application
Group Exercise
① Xamarin.Forms creates asingle binary that can be deployed to Android,
iOSorWindows
a) True
b) False
Flash Quiz
① Xamarin.Forms creates asingle binary that can be deployed to Android,
iOSorWindows
a) True
b) False
Flash Quiz
② You must call before using Xamarin.Forms
a) Forms.Initialize
b) Forms.Init
c) Forms.Setup
d) No setup call necessary
Flash Quiz
② You must call before using Xamarin.Forms
a) Forms.Initialize
b) Forms.Init
c) Forms.Setup
d) No setup call necessary
Flash Quiz
③ Tosupply the initial page for the application, you must set the
property.
a) Application.FirstPage
b) Application.PrimaryPage
c) Application.MainPage
d) Application.MainView
Flash Quiz
③ Tosupply the initial page for the application, you must set the
property.
a) Application.FirstPage
b) Application.PrimaryPage
c) Application.MainPage
d) Application.MainView
Flash Quiz
❖ Xamarin.Forms project structure
❖ Application Components
❖ "Hello, Forms!"
Summary
❖ Layout containers
❖ Adding views
❖ Fine-tuning layout
Tasks
Organizing content
❖ Rather than specifying positions
with coordinates (pixels, dips, etc.),
you uselayout containers to
control how views are positioned
relative to each other
❖ This provides for a more adaptive
layout which is not as sensitive to
dimensions and resolutions
For example, "stacking" views on top of each
other with some spacing between them
Layout containers
StackLayout
❖ Layout Containers organize child elements based on specific rules
StackLayoutplaces children
top-to-bottom (default) or left-to-
right based on Orientation
property setting
❖ Layout Containers organize child elements based on specific rules
Layout containers
StackLayout AbsoluteLayout
AbsoluteLayoutplaces children in
absolute requested positions
based on anchors and bounds
❖ Layout Containers organize child elements based on specific rules
Layout containers
StackLayout Absolute
Layout
Relative
Layout
RelativeLayout uses
constraints to
position the children
❖ Layout Containers organize child elements based on specific rules
Layout containers
StackLayout Absolute
Layout
Relative
Layout
Grid
Grid places
children in defined
rows and columns
Layout containers
StackLayout Absolute
Layout
Relative
Layout
Grid ScrollView
❖ Layout Containers organize child elements based on specific rules
ScrollViewscrolls a
single piece of content
(which isnormally a
layout container)
Adding views to layout containers
❖ Layout containers have aChildren collection property which isused to
hold the views that will be organized by the container
Label label = new Label { Text = "EnterYour Name" }; Entry nameEntry =
new Entry();
StackLayout layout = new StackLayout();
layout.Children.Add(label);
layout.Children.Add(nameEntry);
this.Content= layout;
Views are laid out and rendered in the order they appear in the collection
❖ StackLayout isused to create typical form stylelayout
Working with StackLayout
…. Entry …
Label
Button
Entry
"stacks"the child views top-to-bottom
(vertical) [default]
…or left-to-right (horizontal)
The Orientationproperty can be set to either Horizontalor Verticalto control which
direction the child views are stacked in
Working with StackLayout
❖ StackLayout isused to create typical form style layout,Orientation
property decides the direction that children are stacked
var layout = new StackLayout { Orientation =
StackOrientation.Vertical
};
layout.Children.Add(new Label { Text = "Enter your name:" });
layout.Children.Add(new Entry());
layout.Children.Add(new Button { Text = "OK" });
❖ Grid isalayout panel used to create rows and columns of views,
children identify specific column, row and span
Working with Grid
Column 0 Column 1
Column = 0, Row = 0,
Column = 1, Row= 0
Row Span= 2
Column = 1, Row= 1
Column = 0, Row= 2, Column Span = 2
Row 0
Row 1
Row 2
Adding items to a Grid
❖ Children in Grid must specify the layout properties, or they will default
to the first column/row
Label label = new Label { Text = "EnterYour Name" };
Grid layout = new Grid();
layout.Children.Add(label);
Grid.SetColumn(label,1);
Grid.SetRow(label, 1);
Grid.SetColumnSpan(label,2);
Grid.SetRowSpan(label, 1);
Usestatic methods
defined on Gridto set
layout properties
Adding items to a Grid
❖ Children in Grid must specify the layout properties, or they will default
to the first column/row
Grid layout = new Grid();
...
layout.Children.Add(label, 0, 1);
layout.Children.Add(button, 0, 2, 2,3);
// Left=0andTop=1
// L=0, R=2,T=2,B=3
Can also specify row/column asLeft/Right/Top/Bottom values to Addmethod
Controlling the shape of the grid
❖ Can influence the determined shape and size of the columns and rows
Grid layout = new Grid();
layout.RowDefinitions.Add(new RowDefinition {
Height = new GridLength(100, GridUnitType.Absolute)// 100px
});
layout.RowDefinitions.Add(new RowDefinition {
Height = new GridLength(1, GridUnitType.Auto)// "Auto" size
});
layout.ColumnDefinitions.Add(newColumnDefinition {
Width = new GridLength(1, GridUnitType.Star) // "Star"size
});
Working with RelativeLayout
❖ RelativeLayout allows you to position child views relative totwo
other views, or to the panel itself using constraint-based rules
var layout = new RelativeLayout();
...
layout.Children.Add(label,
Constraint.RelativeToParent(
parent => (0.5 * parent.Width) - 25), //X
Constraint.RelativeToView(button,
(parent, sibling)=> sibling.Y + 5), // Y
Constraint.Constant(50), // Width
Constraint.Constant(50)); // Height
Working with AbsoluteLayout
❖ AbsoluteLayout positions and sizeschildren by absolute values through
either a coordinate (where the view determines it's own size), or a
bounding box
var layout = newAbsoluteLayout();
...
// Can do absolute positions by coordinate point
layout.Children.Add(label1, new Point(100, 100));
// Or use a specific bounding box layout.Children.Add(label2, new Rectangle(20, 20,
100, 25));
❖ AbsoluteLayout can also position and size children proportional to its
own size using coordinates based on a 1x1unit square which represents
apercentage of the container's size
Working with AbsoluteLayout
(0,0)
(0.5,0.5)
(1,1)
(1,0)
(0,1)
Working with AbsoluteLayout
❖ AbsoluteLayout can also position and size children proportional to its
own size using coordinates based on a 1x1 unit square which represents
apercentage of the container's size
var layout = newAbsoluteLayout();
...
// Center at the bottom of the container, take up ½ the space
layout.Children.Add(bottomLabel,new Rectangle (.5, 1, .5, .1),
AbsoluteLayoutFlags.All);
Here we center the label (.5) at the bottom of the container (1)
and take up ½ the space (.5) width and 1/10the space height (.1)
Working with AbsoluteLayout
❖ AbsoluteLayout can also position and size children proportional to its
own size using coordinates based on a 1x1 unit square which represents
apercentage of the container's size
var layout = newAbsoluteLayout();
...
// Stretch image across entire container layout.Children.Add(fillImage,new
Rectangle (0, 0, 1, 1),
AbsoluteLayoutFlags.All);
Here we "fill" the container with an image
[0,0] – [1,1]
❖ Canuseeither Add method, or specific static methods to control the
bounding box and layout flags for children in AbsoluteLayout –this
allows for "runtime" adjustments
Fine-tuning AbsoluteLayout
Label bottomLabel;
void MoveLabelToTopRight(objectsender, EventArgs e)
{
AbsoluteLayout.SetLayoutBounds(bottomLabel,
new Rectangle (1, 0, .5, .1));
AbsoluteLayout.SetLayoutFlags (bottomLabel,
AbsoluteLayoutFlags.All);
}
❖ UseWidthRequest and HeightRequestto askthe layout panel for a
specific size for your views
Element size
Button
var button = new Button();
button.WidthRequest =300;
button.HeightRequest=150;
❖ Margin adds distance from an view to
adjacent views within a managed layout
View Margin
Label
Button
Overloaded constructors give you
several options, including the ability
to set a separate value on each side
Label label = ... Button
button =...
label.Margin = newThickness(10);
button.Margin= new Thickness(10,20);
❖ Padding adds distance between the
inside edges of a layout container and
its children (only available in layouts)
Layout Padding
View
View
View
Grid grid = ...;
grid.Padding = newThickness(10);
❖ The Spacingproperty of StackLayoutand
controls the distance between child elements
StackLayout Spacing
View
View
View
Stack Layout
StackLayout panel = ...;
panel.Spacing = 20;
Spacing
Creating Xamarin.Forms Phoneword
Individual Exercise
① The direction (left-to-right or top-to-bottom) a StackLayout
organizes content iscontrolled by which property?
a) Style
b) Direction
c) Orientation
d) LayoutDirection
Flash Quiz
① The direction (left-to-right or top-to-bottom) a StackLayout
organizes content iscontrolled by which property?
a) Style
b) Direction
c) Orientation
d) LayoutDirection
Flash Quiz
② Which of these controls isnot available in Xamarin.Forms?
a) Button
b) DatePicker
c) ListBox
d) ListView
Flash Quiz
② Which of these controls isnot available in Xamarin.Forms?
a) Button
b) DatePicker
c) ListBox
d) ListView
Flash Quiz
③ Toadjust spacing between children when using the StackLayout
container we can change the property on the stack layout.
a) Margin
b) Padding
c) Spacing
Flash Quiz
③ Toadjust spacing between children when using the StackLayout
container we can change the property on the stack layout.
a) Margin
b) Padding
c) Spacing
Flash Quiz
❖ Layout containers
❖ Adding views
❖ Fine-tuning layout
Summary
Useplatform-specificfeatures
in shared code
❖ Changing the UI per-platform
❖ Using Platform features
❖ Working with DependencyService
Tasks
❖ Xamarin.Forms applications have two projects that work together to
provide the logic + UIfor each executable
Recall: Xamarin.Forms architecture
Portable
Class Library
Platform-
SpecPifliactfporromje-ct
SpecPifliactfporromje-ct
Specific project
▪ shared acrossall platforms
▪ limited access to .NETAPIs
▪ want most of our code here
▪ 1-per platform
▪ code isnot shared
▪ full accessto .NETAPIs
▪ any platform-specific code must
be located in these projects
❖ Device.RuntimePlatformallows your
app to determine the executing
platform
Changing the UI per-platform
switch(Device.RuntimePlatform)
{
case Device.iOS:
...
break;
case Device.Android:
...
break;
case Device.UWP:
...
break;
case Device.macOS:
...
break;
}
❖ Canusethe static Device classto identify the device style
Detecting the platform
if (Device.Idiom==TargetIdiom.Tablet) {
// Code for tablets only
if (Device.RuntimePlatform== Device.iOS) {
// Code for iPad only
}
}
Note that this does not allow for platform-specific codeto be executed, it allows runtime
detection of the platform to execute a unique branch in your shared code
❖ Xamarin.Forms hassupport for dealing with afew, very common
platform-specific features
Using Platform Features
Page.DisplayAlert to
show simple alert
messages
Timer
management using
Device.StartTimer
Device.OpenUri
to launch external apps
based on a URL
scheme
❖ Xamarin.Forms hassupport for dealing with afew, very common
platform-specific features
Using Platform Features
UIThread
marshaling with
Device.BeginInvoke
OnMainThread
Mapping and Location
through
Xamarin.Forms.Maps
Other platform-specific features
❖ Platform features not exposed by
Xamarin.Forms can be used, but will
require some architectural design
▪ code goes into platform-specific
projects
▪ often must (somehow) use code
from your shared logic project
Dialing the phone
would require
platform-specific code
❖ Bestpractice to build an abstraction implemented by the target platform
which defines the platform-specific functionality
Creating abstractions
PhoneDialerIOS
PhoneDialerDroid
PhoneDialerWin
Platform projects implement the
shared dialer interface using the
platform-specific APIs
Shared code defines IDialerinterface to
represent required functionality
publicinterfaceIDialer
{
bool MakeCall(string number);
}
❖ Xamarin.Forms includes a servicelocator called DependencyService
which can be used to register platform-specific implementations and
then locate them through the abstraction in your shared code
Locating dependencies
1
Define an interface or abstract classin the
shared code project (PCL)
public interface IDialer
{
bool MakeCall(string number);
}
❖ Xamarin.Forms includes a servicelocator called DependencyService
which can be used to register platform-specific implementations and
then locate them through the abstraction in your shared code
Locating dependencies
2
Provide implementation of abstraction in
each platform-specific project
class PhoneDialerIOS : IDialer
{
public bool MakeCall(stringnumber) {
// Implementation goes here
}
}
❖ Xamarin.Forms includes a servicelocator called DependencyService
which can be used to register platform-specific implementations and
then locate them through the abstraction in your shared code
Locating dependencies
3
Exposeplatform-specific implementation using assembly-
level attribute in platform-specific project
[assembly: Dependency(typeof(PhoneDialerIOS))]
Implementation type issupplied to
attribute aspart of registration
❖ Xamarin.Forms includes a servicelocator called DependencyService
which can be used to register platform-specific implementations and
then locate them through the abstraction in your shared code
Locating dependencies
4
Retrieve and usethe dependency anywhere using
DependencyService.Get<T>(bothshared and platform
specific projects can usethis API)
IDialer dialer =DependencyService.Get<IDialer>();
if (dialer != null) {
...
}
Request the abstraction and the
implementation will be returned
Adding support for dialing the phone
Individual Exercise
❖ Changing the UI per-platform
❖ Using Platform features
❖ Working with DependencyService
Summary
Thank You!

Contenu connexe

Tendances

Salesforce Developer Garage Seattle: Force.com Canvas
Salesforce Developer Garage Seattle: Force.com CanvasSalesforce Developer Garage Seattle: Force.com Canvas
Salesforce Developer Garage Seattle: Force.com CanvasSalesforce Developers
 
18 Invaluable Lessons About ADF-JSF Interaction
18 Invaluable Lessons About ADF-JSF Interaction18 Invaluable Lessons About ADF-JSF Interaction
18 Invaluable Lessons About ADF-JSF InteractionSteven Davelaar
 
Intro to Force.com Canvas: Running External Apps within the Salesforce UI Web...
Intro to Force.com Canvas: Running External Apps within the Salesforce UI Web...Intro to Force.com Canvas: Running External Apps within the Salesforce UI Web...
Intro to Force.com Canvas: Running External Apps within the Salesforce UI Web...Salesforce Developers
 
Windows Presentation Foundation
Windows Presentation Foundation  Windows Presentation Foundation
Windows Presentation Foundation Deepika Chaudhary
 
10 asp.net session14
10 asp.net session1410 asp.net session14
10 asp.net session14Vivek chan
 
Force.com Canvas - a Quick Introduction
Force.com Canvas - a Quick IntroductionForce.com Canvas - a Quick Introduction
Force.com Canvas - a Quick IntroductionSteven Herod
 
Xamarin Dev Days Madrid 2017 - Xamarin.Forms
Xamarin Dev Days Madrid 2017 -  Xamarin.FormsXamarin Dev Days Madrid 2017 -  Xamarin.Forms
Xamarin Dev Days Madrid 2017 - Xamarin.FormsJavier Suárez Ruiz
 
Customizing Xamarin.Forms UI
Customizing Xamarin.Forms UICustomizing Xamarin.Forms UI
Customizing Xamarin.Forms UIXamarin
 
Dive Deep Into the Force.com Canvas Framework
Dive Deep Into the Force.com Canvas FrameworkDive Deep Into the Force.com Canvas Framework
Dive Deep Into the Force.com Canvas FrameworkSalesforce Developers
 
Twelve ways to make your apps suck less
Twelve ways to make your apps suck lessTwelve ways to make your apps suck less
Twelve ways to make your apps suck lessFons Sonnemans
 
Developing and Deploying Windows 10 Apps
Developing and Deploying Windows 10 AppsDeveloping and Deploying Windows 10 Apps
Developing and Deploying Windows 10 AppsFons Sonnemans
 
WPF For Beginners - Learn in 3 days
WPF For Beginners  - Learn in 3 daysWPF For Beginners  - Learn in 3 days
WPF For Beginners - Learn in 3 daysUdaya Kumar
 
Bulk Profile Operations in Salesforce using BOFC App
Bulk Profile Operations in Salesforce using BOFC AppBulk Profile Operations in Salesforce using BOFC App
Bulk Profile Operations in Salesforce using BOFC AppAtocloud
 
Customizing the Presentation Model and Physical Renderer in Siebel Open UI
Customizing the Presentation Model and Physical Renderer in Siebel Open UICustomizing the Presentation Model and Physical Renderer in Siebel Open UI
Customizing the Presentation Model and Physical Renderer in Siebel Open UITech OneStop
 

Tendances (15)

Salesforce Developer Garage Seattle: Force.com Canvas
Salesforce Developer Garage Seattle: Force.com CanvasSalesforce Developer Garage Seattle: Force.com Canvas
Salesforce Developer Garage Seattle: Force.com Canvas
 
18 Invaluable Lessons About ADF-JSF Interaction
18 Invaluable Lessons About ADF-JSF Interaction18 Invaluable Lessons About ADF-JSF Interaction
18 Invaluable Lessons About ADF-JSF Interaction
 
Intro to Force.com Canvas: Running External Apps within the Salesforce UI Web...
Intro to Force.com Canvas: Running External Apps within the Salesforce UI Web...Intro to Force.com Canvas: Running External Apps within the Salesforce UI Web...
Intro to Force.com Canvas: Running External Apps within the Salesforce UI Web...
 
Windows Presentation Foundation
Windows Presentation Foundation  Windows Presentation Foundation
Windows Presentation Foundation
 
10 asp.net session14
10 asp.net session1410 asp.net session14
10 asp.net session14
 
Force.com Canvas - a Quick Introduction
Force.com Canvas - a Quick IntroductionForce.com Canvas - a Quick Introduction
Force.com Canvas - a Quick Introduction
 
Xamarin Dev Days Madrid 2017 - Xamarin.Forms
Xamarin Dev Days Madrid 2017 -  Xamarin.FormsXamarin Dev Days Madrid 2017 -  Xamarin.Forms
Xamarin Dev Days Madrid 2017 - Xamarin.Forms
 
Customizing Xamarin.Forms UI
Customizing Xamarin.Forms UICustomizing Xamarin.Forms UI
Customizing Xamarin.Forms UI
 
Dive Deep Into the Force.com Canvas Framework
Dive Deep Into the Force.com Canvas FrameworkDive Deep Into the Force.com Canvas Framework
Dive Deep Into the Force.com Canvas Framework
 
SilverlightCh01
SilverlightCh01SilverlightCh01
SilverlightCh01
 
Twelve ways to make your apps suck less
Twelve ways to make your apps suck lessTwelve ways to make your apps suck less
Twelve ways to make your apps suck less
 
Developing and Deploying Windows 10 Apps
Developing and Deploying Windows 10 AppsDeveloping and Deploying Windows 10 Apps
Developing and Deploying Windows 10 Apps
 
WPF For Beginners - Learn in 3 days
WPF For Beginners  - Learn in 3 daysWPF For Beginners  - Learn in 3 days
WPF For Beginners - Learn in 3 days
 
Bulk Profile Operations in Salesforce using BOFC App
Bulk Profile Operations in Salesforce using BOFC AppBulk Profile Operations in Salesforce using BOFC App
Bulk Profile Operations in Salesforce using BOFC App
 
Customizing the Presentation Model and Physical Renderer in Siebel Open UI
Customizing the Presentation Model and Physical Renderer in Siebel Open UICustomizing the Presentation Model and Physical Renderer in Siebel Open UI
Customizing the Presentation Model and Physical Renderer in Siebel Open UI
 

Similaire à Xamarin.Forms a different approach to cross platform natove mobile development

Your First Xamarin.Forms App
Your First Xamarin.Forms AppYour First Xamarin.Forms App
Your First Xamarin.Forms AppCraig Dunn
 
Cross platform mobile app development with Xamarin
Cross platform mobile app development with XamarinCross platform mobile app development with Xamarin
Cross platform mobile app development with XamarinPranav Ainavolu
 
App innovationcircles xamarin
App innovationcircles xamarinApp innovationcircles xamarin
App innovationcircles xamarinMohit Chhabra
 
Building Accessible Apps using NET MAUI.pdf
Building Accessible Apps using NET MAUI.pdfBuilding Accessible Apps using NET MAUI.pdf
Building Accessible Apps using NET MAUI.pdfSivarajAmbat1
 
Xamarin.Forms Hands On Lab (Begineer)
Xamarin.Forms Hands On Lab (Begineer)Xamarin.Forms Hands On Lab (Begineer)
Xamarin.Forms Hands On Lab (Begineer)Cheah Eng Soon
 
11 asp.net session16
11 asp.net session1611 asp.net session16
11 asp.net session16Vivek chan
 
Xamarin forms from zero to hero
Xamarin forms from zero to heroXamarin forms from zero to hero
Xamarin forms from zero to heroCharlin Agramonte
 
Introduction to Palm's Mojo SDK
Introduction to Palm's Mojo SDKIntroduction to Palm's Mojo SDK
Introduction to Palm's Mojo SDKBrendan Lim
 
Introduction to Xamarin.Forms
Introduction to Xamarin.FormsIntroduction to Xamarin.Forms
Introduction to Xamarin.FormsBrad Pillow
 
Building xamarin.forms apps with prism and mvvm
Building xamarin.forms apps with prism and mvvmBuilding xamarin.forms apps with prism and mvvm
Building xamarin.forms apps with prism and mvvmMike Melusky
 
Btb017 David
Btb017 DavidBtb017 David
Btb017 DavidRohit Ray
 
First Steps in Android Development with Eclipse and Xamarin
First Steps in Android Development with Eclipse and XamarinFirst Steps in Android Development with Eclipse and Xamarin
First Steps in Android Development with Eclipse and XamarinSasha Goldshtein
 
APAC Webinar: Say Hello To Xamarin.Forms
APAC Webinar: Say Hello To Xamarin.FormsAPAC Webinar: Say Hello To Xamarin.Forms
APAC Webinar: Say Hello To Xamarin.FormsNish Anil
 
Windows Phone 7: Navigating Between Pages
Windows Phone 7: Navigating Between PagesWindows Phone 7: Navigating Between Pages
Windows Phone 7: Navigating Between PagesJussi Pohjolainen
 

Similaire à Xamarin.Forms a different approach to cross platform natove mobile development (20)

Your First Xamarin.Forms App
Your First Xamarin.Forms AppYour First Xamarin.Forms App
Your First Xamarin.Forms App
 
Cross platform mobile app development with Xamarin
Cross platform mobile app development with XamarinCross platform mobile app development with Xamarin
Cross platform mobile app development with Xamarin
 
App innovationcircles xamarin
App innovationcircles xamarinApp innovationcircles xamarin
App innovationcircles xamarin
 
Building Accessible Apps using NET MAUI.pdf
Building Accessible Apps using NET MAUI.pdfBuilding Accessible Apps using NET MAUI.pdf
Building Accessible Apps using NET MAUI.pdf
 
Xamarin.Forms Hands On Lab (Begineer)
Xamarin.Forms Hands On Lab (Begineer)Xamarin.Forms Hands On Lab (Begineer)
Xamarin.Forms Hands On Lab (Begineer)
 
11 asp.net session16
11 asp.net session1611 asp.net session16
11 asp.net session16
 
pebble - Building apps on pebble
pebble - Building apps on pebblepebble - Building apps on pebble
pebble - Building apps on pebble
 
unit 4.docx
unit 4.docxunit 4.docx
unit 4.docx
 
Xamarin forms from zero to hero
Xamarin forms from zero to heroXamarin forms from zero to hero
Xamarin forms from zero to hero
 
Introduction to Palm's Mojo SDK
Introduction to Palm's Mojo SDKIntroduction to Palm's Mojo SDK
Introduction to Palm's Mojo SDK
 
Introduction to Xamarin.Forms
Introduction to Xamarin.FormsIntroduction to Xamarin.Forms
Introduction to Xamarin.Forms
 
DEVICE CHANNELS
DEVICE CHANNELSDEVICE CHANNELS
DEVICE CHANNELS
 
Building xamarin.forms apps with prism and mvvm
Building xamarin.forms apps with prism and mvvmBuilding xamarin.forms apps with prism and mvvm
Building xamarin.forms apps with prism and mvvm
 
Intro to appcelerator
Intro to appceleratorIntro to appcelerator
Intro to appcelerator
 
Btb017 David
Btb017 DavidBtb017 David
Btb017 David
 
Xamarin Development
Xamarin DevelopmentXamarin Development
Xamarin Development
 
First Steps in Android Development with Eclipse and Xamarin
First Steps in Android Development with Eclipse and XamarinFirst Steps in Android Development with Eclipse and Xamarin
First Steps in Android Development with Eclipse and Xamarin
 
APAC Webinar: Say Hello To Xamarin.Forms
APAC Webinar: Say Hello To Xamarin.FormsAPAC Webinar: Say Hello To Xamarin.Forms
APAC Webinar: Say Hello To Xamarin.Forms
 
Introduction to Xamarin
Introduction to XamarinIntroduction to Xamarin
Introduction to Xamarin
 
Windows Phone 7: Navigating Between Pages
Windows Phone 7: Navigating Between PagesWindows Phone 7: Navigating Between Pages
Windows Phone 7: Navigating Between Pages
 

Plus de Dan Ardelean

CI/CD for mobile development using AppCenter
CI/CD for mobile development using AppCenterCI/CD for mobile development using AppCenter
CI/CD for mobile development using AppCenterDan Ardelean
 
CI/CD for mobile development using Visual Studio App Center
CI/CD for mobile development using Visual Studio App CenterCI/CD for mobile development using Visual Studio App Center
CI/CD for mobile development using Visual Studio App CenterDan Ardelean
 
Visual Studio App Center: CI/CD para mobile devs
Visual Studio App Center: CI/CD para mobile devsVisual Studio App Center: CI/CD para mobile devs
Visual Studio App Center: CI/CD para mobile devsDan Ardelean
 
Desarrollo multiplataforma con el framework .net
Desarrollo multiplataforma con el framework .netDesarrollo multiplataforma con el framework .net
Desarrollo multiplataforma con el framework .netDan Ardelean
 
Xamarin.forms a different approach to native cross platform mobile development
Xamarin.forms a different approach to native cross platform mobile developmentXamarin.forms a different approach to native cross platform mobile development
Xamarin.forms a different approach to native cross platform mobile developmentDan Ardelean
 
Xamarin - Under the bridge
Xamarin - Under the bridgeXamarin - Under the bridge
Xamarin - Under the bridgeDan Ardelean
 
Sviluppo x platform con xamarin
Sviluppo x platform con xamarin Sviluppo x platform con xamarin
Sviluppo x platform con xamarin Dan Ardelean
 
Xamarin - why not ?
Xamarin -  why not ?Xamarin -  why not ?
Xamarin - why not ?Dan Ardelean
 
Share more code on iOS, Android and Windows with Portable Class Libraries
Share more code on iOS, Android and Windows with Portable Class LibrariesShare more code on iOS, Android and Windows with Portable Class Libraries
Share more code on iOS, Android and Windows with Portable Class LibrariesDan Ardelean
 
iBeacons for everyone
iBeacons for everyoneiBeacons for everyone
iBeacons for everyoneDan Ardelean
 
Xamarin Dev Days 2016 introduction to xamarin
Xamarin Dev Days 2016   introduction to xamarinXamarin Dev Days 2016   introduction to xamarin
Xamarin Dev Days 2016 introduction to xamarinDan Ardelean
 
A new world of possibilities for contextual awareness with beacons
A new world of possibilities for contextual awareness with beaconsA new world of possibilities for contextual awareness with beacons
A new world of possibilities for contextual awareness with beaconsDan Ardelean
 
C sharp day 2015 c# patterns- cross-platform
C sharp day 2015   c# patterns- cross-platform  C sharp day 2015   c# patterns- cross-platform
C sharp day 2015 c# patterns- cross-platform Dan Ardelean
 
Utilizzo dei beacon con windows 10
Utilizzo dei beacon con windows 10Utilizzo dei beacon con windows 10
Utilizzo dei beacon con windows 10Dan Ardelean
 
Develop for Windows 10 (Preview)
Develop for Windows 10 (Preview)Develop for Windows 10 (Preview)
Develop for Windows 10 (Preview)Dan Ardelean
 
Community Days 2015 Introduzione a Xamarin
Community Days 2015  Introduzione a XamarinCommunity Days 2015  Introduzione a Xamarin
Community Days 2015 Introduzione a XamarinDan Ardelean
 
Sviluppo di app cross platform con xamarin e C#
Sviluppo di app cross platform con xamarin e C#Sviluppo di app cross platform con xamarin e C#
Sviluppo di app cross platform con xamarin e C#Dan Ardelean
 
WP04 -Sensori e hardware con Windows Phone 8.1
WP04 -Sensori e hardware con Windows Phone 8.1WP04 -Sensori e hardware con Windows Phone 8.1
WP04 -Sensori e hardware con Windows Phone 8.1Dan Ardelean
 
Bluetooth LE & Lumia Sensor Core
Bluetooth LE & Lumia Sensor CoreBluetooth LE & Lumia Sensor Core
Bluetooth LE & Lumia Sensor CoreDan Ardelean
 
Introduction to Xamarin 3
Introduction to Xamarin 3Introduction to Xamarin 3
Introduction to Xamarin 3Dan Ardelean
 

Plus de Dan Ardelean (20)

CI/CD for mobile development using AppCenter
CI/CD for mobile development using AppCenterCI/CD for mobile development using AppCenter
CI/CD for mobile development using AppCenter
 
CI/CD for mobile development using Visual Studio App Center
CI/CD for mobile development using Visual Studio App CenterCI/CD for mobile development using Visual Studio App Center
CI/CD for mobile development using Visual Studio App Center
 
Visual Studio App Center: CI/CD para mobile devs
Visual Studio App Center: CI/CD para mobile devsVisual Studio App Center: CI/CD para mobile devs
Visual Studio App Center: CI/CD para mobile devs
 
Desarrollo multiplataforma con el framework .net
Desarrollo multiplataforma con el framework .netDesarrollo multiplataforma con el framework .net
Desarrollo multiplataforma con el framework .net
 
Xamarin.forms a different approach to native cross platform mobile development
Xamarin.forms a different approach to native cross platform mobile developmentXamarin.forms a different approach to native cross platform mobile development
Xamarin.forms a different approach to native cross platform mobile development
 
Xamarin - Under the bridge
Xamarin - Under the bridgeXamarin - Under the bridge
Xamarin - Under the bridge
 
Sviluppo x platform con xamarin
Sviluppo x platform con xamarin Sviluppo x platform con xamarin
Sviluppo x platform con xamarin
 
Xamarin - why not ?
Xamarin -  why not ?Xamarin -  why not ?
Xamarin - why not ?
 
Share more code on iOS, Android and Windows with Portable Class Libraries
Share more code on iOS, Android and Windows with Portable Class LibrariesShare more code on iOS, Android and Windows with Portable Class Libraries
Share more code on iOS, Android and Windows with Portable Class Libraries
 
iBeacons for everyone
iBeacons for everyoneiBeacons for everyone
iBeacons for everyone
 
Xamarin Dev Days 2016 introduction to xamarin
Xamarin Dev Days 2016   introduction to xamarinXamarin Dev Days 2016   introduction to xamarin
Xamarin Dev Days 2016 introduction to xamarin
 
A new world of possibilities for contextual awareness with beacons
A new world of possibilities for contextual awareness with beaconsA new world of possibilities for contextual awareness with beacons
A new world of possibilities for contextual awareness with beacons
 
C sharp day 2015 c# patterns- cross-platform
C sharp day 2015   c# patterns- cross-platform  C sharp day 2015   c# patterns- cross-platform
C sharp day 2015 c# patterns- cross-platform
 
Utilizzo dei beacon con windows 10
Utilizzo dei beacon con windows 10Utilizzo dei beacon con windows 10
Utilizzo dei beacon con windows 10
 
Develop for Windows 10 (Preview)
Develop for Windows 10 (Preview)Develop for Windows 10 (Preview)
Develop for Windows 10 (Preview)
 
Community Days 2015 Introduzione a Xamarin
Community Days 2015  Introduzione a XamarinCommunity Days 2015  Introduzione a Xamarin
Community Days 2015 Introduzione a Xamarin
 
Sviluppo di app cross platform con xamarin e C#
Sviluppo di app cross platform con xamarin e C#Sviluppo di app cross platform con xamarin e C#
Sviluppo di app cross platform con xamarin e C#
 
WP04 -Sensori e hardware con Windows Phone 8.1
WP04 -Sensori e hardware con Windows Phone 8.1WP04 -Sensori e hardware con Windows Phone 8.1
WP04 -Sensori e hardware con Windows Phone 8.1
 
Bluetooth LE & Lumia Sensor Core
Bluetooth LE & Lumia Sensor CoreBluetooth LE & Lumia Sensor Core
Bluetooth LE & Lumia Sensor Core
 
Introduction to Xamarin 3
Introduction to Xamarin 3Introduction to Xamarin 3
Introduction to Xamarin 3
 

Dernier

Android Application Components with Implementation & Examples
Android Application Components with Implementation & ExamplesAndroid Application Components with Implementation & Examples
Android Application Components with Implementation & ExamplesChandrakantDivate1
 
Mobile Application Development-Components and Layouts
Mobile Application Development-Components and LayoutsMobile Application Development-Components and Layouts
Mobile Application Development-Components and LayoutsChandrakantDivate1
 
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCRFULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCRnishacall1
 
Leading Mobile App Development Companies in India (2).pdf
Leading Mobile App Development Companies in India (2).pdfLeading Mobile App Development Companies in India (2).pdf
Leading Mobile App Development Companies in India (2).pdfCWS Technology
 
Mobile Application Development-Android and It’s Tools
Mobile Application Development-Android and It’s ToolsMobile Application Development-Android and It’s Tools
Mobile Application Development-Android and It’s ToolsChandrakantDivate1
 
9999266834 Call Girls In Noida Sector 52 (Delhi) Call Girl Service
9999266834 Call Girls In Noida Sector 52 (Delhi) Call Girl Service9999266834 Call Girls In Noida Sector 52 (Delhi) Call Girl Service
9999266834 Call Girls In Noida Sector 52 (Delhi) Call Girl Servicenishacall1
 
Thane 💋 Call Girls 7738631006 💋 Call Girls in Thane Escort service book now. ...
Thane 💋 Call Girls 7738631006 💋 Call Girls in Thane Escort service book now. ...Thane 💋 Call Girls 7738631006 💋 Call Girls in Thane Escort service book now. ...
Thane 💋 Call Girls 7738631006 💋 Call Girls in Thane Escort service book now. ...Pooja Nehwal
 

Dernier (8)

Android Application Components with Implementation & Examples
Android Application Components with Implementation & ExamplesAndroid Application Components with Implementation & Examples
Android Application Components with Implementation & Examples
 
Mobile Application Development-Components and Layouts
Mobile Application Development-Components and LayoutsMobile Application Development-Components and Layouts
Mobile Application Development-Components and Layouts
 
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCRFULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
FULL ENJOY - 9999218229 Call Girls in {Mahipalpur}| Delhi NCR
 
Leading Mobile App Development Companies in India (2).pdf
Leading Mobile App Development Companies in India (2).pdfLeading Mobile App Development Companies in India (2).pdf
Leading Mobile App Development Companies in India (2).pdf
 
Mobile Application Development-Android and It’s Tools
Mobile Application Development-Android and It’s ToolsMobile Application Development-Android and It’s Tools
Mobile Application Development-Android and It’s Tools
 
Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)
Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)
Obat Penggugur Kandungan Di Apotik Kimia Farma (087776558899)
 
9999266834 Call Girls In Noida Sector 52 (Delhi) Call Girl Service
9999266834 Call Girls In Noida Sector 52 (Delhi) Call Girl Service9999266834 Call Girls In Noida Sector 52 (Delhi) Call Girl Service
9999266834 Call Girls In Noida Sector 52 (Delhi) Call Girl Service
 
Thane 💋 Call Girls 7738631006 💋 Call Girls in Thane Escort service book now. ...
Thane 💋 Call Girls 7738631006 💋 Call Girls in Thane Escort service book now. ...Thane 💋 Call Girls 7738631006 💋 Call Girls in Thane Escort service book now. ...
Thane 💋 Call Girls 7738631006 💋 Call Girls in Thane Escort service book now. ...
 

Xamarin.Forms a different approach to cross platform natove mobile development

  • 1. https://goo.gl/Pg7x9q Xamarin.Forms a different approach to cross-platform native mobile development https://goo.gl/Pg7x9q
  • 2. 1. Create asingle screen cross- platform application 2. Arrange the UIusing Layouts 3. Useplatform-specific features in shared code Objectives
  • 3. Create a single screen cross-platform application
  • 4. ❖ Traditional vs. Xamarin.Forms ❖ Xamarin.Forms project structure ❖ Application Components ❖ "Hello, Forms!" Tasks
  • 5. ❖ Traditional Xamarin approach allows for shared business logic and non- sharable platform-specific code for the UI layer Xamarin.iOS and Xamarin.Android iOS C# UI Window s C# UI Android C# UI Shared C# business logic Xamarin.iOS and Xamarin.Android
  • 6. ❖ Xamarin.Forms allows you to describe the UIonce using ashared set of elements which create a native UIat runtime Xamarin.Forms iOS C# UI Window s C# UI Android C# UI Shared C# business logic Shared C# UI Shared C# business logic Xamarin.iOS and Xamarin.Android Xamarin.Forms
  • 7. ❖ Xamarin.Forms isa cross- platform UIframework to create mobile apps for: ▪ Android 4.0+ ▪ iOS 8.0+ ▪ Windows 10 What is Xamarin.Forms? Flexible Layout Standard Controls Custom Controls Data Binding Engine XAML Navigation Styles + Triggers Maps
  • 8. Xamarin.Forms platform support Shared C# UI Shared C# logic ❖ Xamarin.Forms supports abroad selection of mobile and desktop platforms and UI frameworks iOS mac
  • 9. ❖ Visual Studio for Windows includes built-in project templates for Xamarin.Forms applications Creating a Xamarin.Forms App [Windows] Available under Cross-Platform
  • 10. ❖ Visual Studio for Mac includes built-in project templates for Xamarin.Forms applications Creating a Xamarin.Forms App [Mac] After selecting your template, a project wizard walks through the available options
  • 11. Project Structure ❖ The Xamarin CrossPlatform App project template creates several related projects Platform-specific projects act as "host" to create native application PCLor SAPused to hold shared code that defines UIand logic
  • 12. ❖ Most of your code will go into the PCLused for shared logic + UI Project Structure - PCL Default template creates anApp classwhich decides the initial screen for the application
  • 13. ❖ Platform-specific projects usethe shared code (PCLor SAP),but not the other way around ❖ Xamarin.Forms defines the UIand behavior in the PCLor SAP(shared) and then calls it from each platform-specific project Project Structure - Dependencies Shared Code iOS project Android project Windows project
  • 14. ❖ Should update Xamarin.Forms Nuget package when starting anew project Xamarin.Forms updates [Windows]
  • 15. ❖ Should update Xamarin.Forms Nuget package when starting anew project Xamarin.Forms updates [Mac]
  • 17. ❖ Xamarin.Forms applications have two required components which are provided by the template Xamarin.Forms app anatomy Application Page(s) Provides initialization for the application Represents a single screen to display
  • 18. Xamarin.Forms Application ❖ Applicationclassprovides a singleton which manages: ▪ Lifecycle methods ▪ Modal navigation notifications ▪ Currently displayed page ▪ Application state persistence ❖ New projects will have a derived implementation named App Note: Windows apps also have an Application class,make sure not to confuse them!
  • 19. ❖ Application classprovides lifecycle methods which can be used to manage persistence and refresh your data Xamarin.Forms Application public classApp :Application { ... protected override void OnStart() {} protected override void OnSleep() {} protected override void OnResume() {} } UseOnStart to initialize and/or reload your app's data UseOnSleep tosavechanges or persist information UseOnResumeto refresh your displayed data
  • 20. ❖ Application classalso includes astring object property bag which ispersisted between app launches Persisting information // Save off username in globalpropertybag Application.Current.Properties["username"] = username.Text; // Restore the username before it is displayed if (Application.Current.Properties.ContainsKey("username")) { var uname =Application.Current.Properties["username"]as string ?? ""; username.Text= uname; }
  • 21. ❖ Application UIisdefined in terms of pagesandviews Creating the application UI Pagerepresents a single screen displayed in the app OK Name:Views are the UI controls the user interacts with
  • 22. Pages Content ❖ Page isan abstract classused to define a single screenof content ▪ derived types provide specific visualization / behavior Displays a single piece of content (visual thing)
  • 23. ❖ Page isan abstract classused to define a single screenof content ▪ derived types provide specific visualization / behavior Pages Content Master Detail Manages two panes of information
  • 24. ❖ Page isan abstract classused to define a single screenof content ▪ derived types provide specific visualization / behavior Pages Content Master Detail Navigation Manages a stack of pages with navigation bar
  • 25. ❖ Page isan abstract classused to define a single screenof content ▪ derived types provide specific visualization / behavior Pages Content Master Detail Navigation Tabbed Pagethat navigates between children using tab bar
  • 26. Adding a new ContentPage to aXamarin.Forms application Demonstration
  • 27. ❖ View isthe base classfor all visual controls, most standard controls are present Views Label Image SearchBar Entry ProgressBar ActivityIndicator Button Slider OpenGLView Editor Stepper WebView DatePicker Switch ListView BoxView TimePicker Frame Picker
  • 28. ❖ Button provides aclickable surface withtext Views - Button OK var okButton = new Button() { Text = "OK" }; okButton.Clicked+= OnClick; void OnClick(object sender, EventArgs e) { ... }
  • 29. Views - Label ❖ UseaLabel to display read-only textblocks Hello, Forms! var hello = new Label() { Text = "Hello,Forms!", HorizontalTextAlignment= TextAlignment.Center, TextColor = Color.Blue, FontFamily = "Arial" };
  • 30. ❖ Usean Entry control if you want the user to provide input with an on- screen or hardware keyboard Views - Entry Hello var edit = new Entry() { Keyboard = Keyboard.Text, PlaceholderText= "Enter Text" };
  • 31. ❖ Platform defines arenderer for each view that turns each view into the appropriate platform-specific control Rendering views var button= new Button{ Text = "ClickMe!" }; UIdefined using a Xamarin.Forms Button Android.Widget.Button UIKit.UIButton Windows.UI.Xaml.Controls.Button
  • 32. Visual adjustments ❖ Views utilize properties to adjust visual appearance and behavior var numEntry = new Entry { Placeholder = "Enter Number", Keyboard = Keyboard.Numeric }; var callButton = new Button { Text = "Call", BackgroundColor = Color.Blue, TextColor = Color.White };
  • 33. ❖ Controls useevents to provide interaction behavior, should be very familiar model for most .NET developers Providing Behavior var numEntry = new Entry { ... }; numEntry.TextChanged += OnTextChanged; ... void OnTextChanged (object sender, string newValue) { ... } Youcan usetraditional delegates, anonymous methods, or lambdas to handle events
  • 34. Creating our first Xamarin.Forms application Group Exercise
  • 35. ① Xamarin.Forms creates asingle binary that can be deployed to Android, iOSorWindows a) True b) False Flash Quiz
  • 36. ① Xamarin.Forms creates asingle binary that can be deployed to Android, iOSorWindows a) True b) False Flash Quiz
  • 37. ② You must call before using Xamarin.Forms a) Forms.Initialize b) Forms.Init c) Forms.Setup d) No setup call necessary Flash Quiz
  • 38. ② You must call before using Xamarin.Forms a) Forms.Initialize b) Forms.Init c) Forms.Setup d) No setup call necessary Flash Quiz
  • 39. ③ Tosupply the initial page for the application, you must set the property. a) Application.FirstPage b) Application.PrimaryPage c) Application.MainPage d) Application.MainView Flash Quiz
  • 40. ③ Tosupply the initial page for the application, you must set the property. a) Application.FirstPage b) Application.PrimaryPage c) Application.MainPage d) Application.MainView Flash Quiz
  • 41. ❖ Xamarin.Forms project structure ❖ Application Components ❖ "Hello, Forms!" Summary
  • 42. ❖ Layout containers ❖ Adding views ❖ Fine-tuning layout Tasks
  • 43. Organizing content ❖ Rather than specifying positions with coordinates (pixels, dips, etc.), you uselayout containers to control how views are positioned relative to each other ❖ This provides for a more adaptive layout which is not as sensitive to dimensions and resolutions For example, "stacking" views on top of each other with some spacing between them
  • 44. Layout containers StackLayout ❖ Layout Containers organize child elements based on specific rules StackLayoutplaces children top-to-bottom (default) or left-to- right based on Orientation property setting
  • 45. ❖ Layout Containers organize child elements based on specific rules Layout containers StackLayout AbsoluteLayout AbsoluteLayoutplaces children in absolute requested positions based on anchors and bounds
  • 46. ❖ Layout Containers organize child elements based on specific rules Layout containers StackLayout Absolute Layout Relative Layout RelativeLayout uses constraints to position the children
  • 47. ❖ Layout Containers organize child elements based on specific rules Layout containers StackLayout Absolute Layout Relative Layout Grid Grid places children in defined rows and columns
  • 48. Layout containers StackLayout Absolute Layout Relative Layout Grid ScrollView ❖ Layout Containers organize child elements based on specific rules ScrollViewscrolls a single piece of content (which isnormally a layout container)
  • 49. Adding views to layout containers ❖ Layout containers have aChildren collection property which isused to hold the views that will be organized by the container Label label = new Label { Text = "EnterYour Name" }; Entry nameEntry = new Entry(); StackLayout layout = new StackLayout(); layout.Children.Add(label); layout.Children.Add(nameEntry); this.Content= layout; Views are laid out and rendered in the order they appear in the collection
  • 50. ❖ StackLayout isused to create typical form stylelayout Working with StackLayout …. Entry … Label Button Entry "stacks"the child views top-to-bottom (vertical) [default] …or left-to-right (horizontal) The Orientationproperty can be set to either Horizontalor Verticalto control which direction the child views are stacked in
  • 51. Working with StackLayout ❖ StackLayout isused to create typical form style layout,Orientation property decides the direction that children are stacked var layout = new StackLayout { Orientation = StackOrientation.Vertical }; layout.Children.Add(new Label { Text = "Enter your name:" }); layout.Children.Add(new Entry()); layout.Children.Add(new Button { Text = "OK" });
  • 52. ❖ Grid isalayout panel used to create rows and columns of views, children identify specific column, row and span Working with Grid Column 0 Column 1 Column = 0, Row = 0, Column = 1, Row= 0 Row Span= 2 Column = 1, Row= 1 Column = 0, Row= 2, Column Span = 2 Row 0 Row 1 Row 2
  • 53. Adding items to a Grid ❖ Children in Grid must specify the layout properties, or they will default to the first column/row Label label = new Label { Text = "EnterYour Name" }; Grid layout = new Grid(); layout.Children.Add(label); Grid.SetColumn(label,1); Grid.SetRow(label, 1); Grid.SetColumnSpan(label,2); Grid.SetRowSpan(label, 1); Usestatic methods defined on Gridto set layout properties
  • 54. Adding items to a Grid ❖ Children in Grid must specify the layout properties, or they will default to the first column/row Grid layout = new Grid(); ... layout.Children.Add(label, 0, 1); layout.Children.Add(button, 0, 2, 2,3); // Left=0andTop=1 // L=0, R=2,T=2,B=3 Can also specify row/column asLeft/Right/Top/Bottom values to Addmethod
  • 55. Controlling the shape of the grid ❖ Can influence the determined shape and size of the columns and rows Grid layout = new Grid(); layout.RowDefinitions.Add(new RowDefinition { Height = new GridLength(100, GridUnitType.Absolute)// 100px }); layout.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Auto)// "Auto" size }); layout.ColumnDefinitions.Add(newColumnDefinition { Width = new GridLength(1, GridUnitType.Star) // "Star"size });
  • 56. Working with RelativeLayout ❖ RelativeLayout allows you to position child views relative totwo other views, or to the panel itself using constraint-based rules var layout = new RelativeLayout(); ... layout.Children.Add(label, Constraint.RelativeToParent( parent => (0.5 * parent.Width) - 25), //X Constraint.RelativeToView(button, (parent, sibling)=> sibling.Y + 5), // Y Constraint.Constant(50), // Width Constraint.Constant(50)); // Height
  • 57. Working with AbsoluteLayout ❖ AbsoluteLayout positions and sizeschildren by absolute values through either a coordinate (where the view determines it's own size), or a bounding box var layout = newAbsoluteLayout(); ... // Can do absolute positions by coordinate point layout.Children.Add(label1, new Point(100, 100)); // Or use a specific bounding box layout.Children.Add(label2, new Rectangle(20, 20, 100, 25));
  • 58. ❖ AbsoluteLayout can also position and size children proportional to its own size using coordinates based on a 1x1unit square which represents apercentage of the container's size Working with AbsoluteLayout (0,0) (0.5,0.5) (1,1) (1,0) (0,1)
  • 59. Working with AbsoluteLayout ❖ AbsoluteLayout can also position and size children proportional to its own size using coordinates based on a 1x1 unit square which represents apercentage of the container's size var layout = newAbsoluteLayout(); ... // Center at the bottom of the container, take up ½ the space layout.Children.Add(bottomLabel,new Rectangle (.5, 1, .5, .1), AbsoluteLayoutFlags.All); Here we center the label (.5) at the bottom of the container (1) and take up ½ the space (.5) width and 1/10the space height (.1)
  • 60. Working with AbsoluteLayout ❖ AbsoluteLayout can also position and size children proportional to its own size using coordinates based on a 1x1 unit square which represents apercentage of the container's size var layout = newAbsoluteLayout(); ... // Stretch image across entire container layout.Children.Add(fillImage,new Rectangle (0, 0, 1, 1), AbsoluteLayoutFlags.All); Here we "fill" the container with an image [0,0] – [1,1]
  • 61. ❖ Canuseeither Add method, or specific static methods to control the bounding box and layout flags for children in AbsoluteLayout –this allows for "runtime" adjustments Fine-tuning AbsoluteLayout Label bottomLabel; void MoveLabelToTopRight(objectsender, EventArgs e) { AbsoluteLayout.SetLayoutBounds(bottomLabel, new Rectangle (1, 0, .5, .1)); AbsoluteLayout.SetLayoutFlags (bottomLabel, AbsoluteLayoutFlags.All); }
  • 62. ❖ UseWidthRequest and HeightRequestto askthe layout panel for a specific size for your views Element size Button var button = new Button(); button.WidthRequest =300; button.HeightRequest=150;
  • 63. ❖ Margin adds distance from an view to adjacent views within a managed layout View Margin Label Button Overloaded constructors give you several options, including the ability to set a separate value on each side Label label = ... Button button =... label.Margin = newThickness(10); button.Margin= new Thickness(10,20);
  • 64. ❖ Padding adds distance between the inside edges of a layout container and its children (only available in layouts) Layout Padding View View View Grid grid = ...; grid.Padding = newThickness(10);
  • 65. ❖ The Spacingproperty of StackLayoutand controls the distance between child elements StackLayout Spacing View View View Stack Layout StackLayout panel = ...; panel.Spacing = 20; Spacing
  • 67. ① The direction (left-to-right or top-to-bottom) a StackLayout organizes content iscontrolled by which property? a) Style b) Direction c) Orientation d) LayoutDirection Flash Quiz
  • 68. ① The direction (left-to-right or top-to-bottom) a StackLayout organizes content iscontrolled by which property? a) Style b) Direction c) Orientation d) LayoutDirection Flash Quiz
  • 69. ② Which of these controls isnot available in Xamarin.Forms? a) Button b) DatePicker c) ListBox d) ListView Flash Quiz
  • 70. ② Which of these controls isnot available in Xamarin.Forms? a) Button b) DatePicker c) ListBox d) ListView Flash Quiz
  • 71. ③ Toadjust spacing between children when using the StackLayout container we can change the property on the stack layout. a) Margin b) Padding c) Spacing Flash Quiz
  • 72. ③ Toadjust spacing between children when using the StackLayout container we can change the property on the stack layout. a) Margin b) Padding c) Spacing Flash Quiz
  • 73. ❖ Layout containers ❖ Adding views ❖ Fine-tuning layout Summary
  • 75. ❖ Changing the UI per-platform ❖ Using Platform features ❖ Working with DependencyService Tasks
  • 76. ❖ Xamarin.Forms applications have two projects that work together to provide the logic + UIfor each executable Recall: Xamarin.Forms architecture Portable Class Library Platform- SpecPifliactfporromje-ct SpecPifliactfporromje-ct Specific project ▪ shared acrossall platforms ▪ limited access to .NETAPIs ▪ want most of our code here ▪ 1-per platform ▪ code isnot shared ▪ full accessto .NETAPIs ▪ any platform-specific code must be located in these projects
  • 77. ❖ Device.RuntimePlatformallows your app to determine the executing platform Changing the UI per-platform switch(Device.RuntimePlatform) { case Device.iOS: ... break; case Device.Android: ... break; case Device.UWP: ... break; case Device.macOS: ... break; }
  • 78. ❖ Canusethe static Device classto identify the device style Detecting the platform if (Device.Idiom==TargetIdiom.Tablet) { // Code for tablets only if (Device.RuntimePlatform== Device.iOS) { // Code for iPad only } } Note that this does not allow for platform-specific codeto be executed, it allows runtime detection of the platform to execute a unique branch in your shared code
  • 79. ❖ Xamarin.Forms hassupport for dealing with afew, very common platform-specific features Using Platform Features Page.DisplayAlert to show simple alert messages Timer management using Device.StartTimer Device.OpenUri to launch external apps based on a URL scheme
  • 80. ❖ Xamarin.Forms hassupport for dealing with afew, very common platform-specific features Using Platform Features UIThread marshaling with Device.BeginInvoke OnMainThread Mapping and Location through Xamarin.Forms.Maps
  • 81. Other platform-specific features ❖ Platform features not exposed by Xamarin.Forms can be used, but will require some architectural design ▪ code goes into platform-specific projects ▪ often must (somehow) use code from your shared logic project Dialing the phone would require platform-specific code
  • 82. ❖ Bestpractice to build an abstraction implemented by the target platform which defines the platform-specific functionality Creating abstractions PhoneDialerIOS PhoneDialerDroid PhoneDialerWin Platform projects implement the shared dialer interface using the platform-specific APIs Shared code defines IDialerinterface to represent required functionality publicinterfaceIDialer { bool MakeCall(string number); }
  • 83. ❖ Xamarin.Forms includes a servicelocator called DependencyService which can be used to register platform-specific implementations and then locate them through the abstraction in your shared code Locating dependencies 1 Define an interface or abstract classin the shared code project (PCL) public interface IDialer { bool MakeCall(string number); }
  • 84. ❖ Xamarin.Forms includes a servicelocator called DependencyService which can be used to register platform-specific implementations and then locate them through the abstraction in your shared code Locating dependencies 2 Provide implementation of abstraction in each platform-specific project class PhoneDialerIOS : IDialer { public bool MakeCall(stringnumber) { // Implementation goes here } }
  • 85. ❖ Xamarin.Forms includes a servicelocator called DependencyService which can be used to register platform-specific implementations and then locate them through the abstraction in your shared code Locating dependencies 3 Exposeplatform-specific implementation using assembly- level attribute in platform-specific project [assembly: Dependency(typeof(PhoneDialerIOS))] Implementation type issupplied to attribute aspart of registration
  • 86. ❖ Xamarin.Forms includes a servicelocator called DependencyService which can be used to register platform-specific implementations and then locate them through the abstraction in your shared code Locating dependencies 4 Retrieve and usethe dependency anywhere using DependencyService.Get<T>(bothshared and platform specific projects can usethis API) IDialer dialer =DependencyService.Get<IDialer>(); if (dialer != null) { ... } Request the abstraction and the implementation will be returned
  • 87. Adding support for dialing the phone Individual Exercise
  • 88. ❖ Changing the UI per-platform ❖ Using Platform features ❖ Working with DependencyService Summary