workshop-part2 introduction to xamarinsddconf.com/brands/sdd/library/xamarin_part_2.pdfxamarin +...

23
4/25/15 1 © 2014 Xamarin.All rights reserved.

Upload: others

Post on 07-Jun-2020

17 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Workshop-Part2 Introduction to Xamarinsddconf.com/brands/sdd/library/Xamarin_Part_2.pdfXamarin + Xamarin.Forms With Xamarin.Forms: more code-sharing, native controls Traditional Xamarin

4/25/15

1©   2014  Xamarin.  All   rights  reserved.

§§§§§

Page 2: Workshop-Part2 Introduction to Xamarinsddconf.com/brands/sdd/library/Xamarin_Part_2.pdfXamarin + Xamarin.Forms With Xamarin.Forms: more code-sharing, native controls Traditional Xamarin

4/25/15

2©   2014  Xamarin.  All   rights  reserved.

Xamarin + Xamarin.FormsWith Xamarin.Forms:

more code-sharing, native controlsTraditional Xamarin approach

Shared UI Code

Page 3: Workshop-Part2 Introduction to Xamarinsddconf.com/brands/sdd/library/Xamarin_Part_2.pdfXamarin + Xamarin.Forms With Xamarin.Forms: more code-sharing, native controls Traditional Xamarin

4/25/15

3©   2014  Xamarin.  All   rights  reserved.

Metroon for iOS

Page 4: Workshop-Part2 Introduction to Xamarinsddconf.com/brands/sdd/library/Xamarin_Part_2.pdfXamarin + Xamarin.Forms With Xamarin.Forms: more code-sharing, native controls Traditional Xamarin

4/25/15

4©   2014  Xamarin.  All   rights  reserved.

What’s Included

Shared UI Code

Flexible Layout

Standard Controls

Multi-Page

Navigation

Custom Controls

Data Binding Engine

XAML

Page 5: Workshop-Part2 Introduction to Xamarinsddconf.com/brands/sdd/library/Xamarin_Part_2.pdfXamarin + Xamarin.Forms With Xamarin.Forms: more code-sharing, native controls Traditional Xamarin

4/25/15

5©   2014  Xamarin.  All   rights  reserved.

Platform-specific projects act as "host" to create native application

Portable Class Library or Shared Project used to hold shared code that defines UI and logic

Pages

Content MasterDetail Navigation Tabbed Carousel

Page 6: Workshop-Part2 Introduction to Xamarinsddconf.com/brands/sdd/library/Xamarin_Part_2.pdfXamarin + Xamarin.Forms With Xamarin.Forms: more code-sharing, native controls Traditional Xamarin

4/25/15

6©   2014  Xamarin.  All   rights  reserved.

Layouts

Stack Absolute Relative Grid ContentView ScrollView Frame

Controls

ActivityIndicator BoxView Button DatePicker Editor

Entry Image Label ListView Map

OpenGLView Picker ProgressBar SearchBar Slider

Stepper TableView TimePicker WebView EntryCell

ImageCell SwitchCell TextCell ViewCell

Page 7: Workshop-Part2 Introduction to Xamarinsddconf.com/brands/sdd/library/Xamarin_Part_2.pdfXamarin + Xamarin.Forms With Xamarin.Forms: more code-sharing, native controls Traditional Xamarin

4/25/15

7©   2014  Xamarin.  All   rights  reserved.

§§§

ContentPage

Control

Content property

Page 8: Workshop-Part2 Introduction to Xamarinsddconf.com/brands/sdd/library/Xamarin_Part_2.pdfXamarin + Xamarin.Forms With Xamarin.Forms: more code-sharing, native controls Traditional Xamarin

4/25/15

8©   2014  Xamarin.  All   rights  reserved.

ContentPage

Layout

Content property

Control

Control

Control

Control

Children

Control

Demonstration

Page 9: Workshop-Part2 Introduction to Xamarinsddconf.com/brands/sdd/library/Xamarin_Part_2.pdfXamarin + Xamarin.Forms With Xamarin.Forms: more code-sharing, native controls Traditional Xamarin

4/25/15

9©   2014  Xamarin.  All   rights  reserved.

var entry = new Entry{

Placeholder = "Enter text",Keyboard = Keyboard.Email

};

entry.TextChanged += (sender, e) => {// Input changed

};

Controls expose properties to alter visualization

Controls expose events to provide interactive behavior

Demonstration

Page 10: Workshop-Part2 Introduction to Xamarinsddconf.com/brands/sdd/library/Xamarin_Part_2.pdfXamarin + Xamarin.Forms With Xamarin.Forms: more code-sharing, native controls Traditional Xamarin

4/25/15

10©   2014  Xamarin.  All   rights  reserved.

> toolable> human readable> extensible

Page 11: Workshop-Part2 Introduction to Xamarinsddconf.com/brands/sdd/library/Xamarin_Part_2.pdfXamarin + Xamarin.Forms With Xamarin.Forms: more code-sharing, native controls Traditional Xamarin

4/25/15

11©   2014  Xamarin.  All   rights  reserved.

shared UI and code

XAML file (UI)

C# file (behavior)

Disclosure arrow collapses the C# file and indicates these files go together

Page 12: Workshop-Part2 Introduction to Xamarinsddconf.com/brands/sdd/library/Xamarin_Part_2.pdfXamarin + Xamarin.Forms With Xamarin.Forms: more code-sharing, native controls Traditional Xamarin

4/25/15

12©   2014  Xamarin.  All   rights  reserved.

§§§§

<?xml version="1.0" encoding="UTF-­‐8" ?><ContentPage ...>

<StackLayout Padding="20" Spacing="10"><Label Text="Enter a Phoneword:" /><Entry Placeholder="Number" /><Button Text="Translate" /><Button Text="Call" IsEnabled="False" />

</StackLayout></ContentPage>

XML based: case sensitive, open tags must be closed, etc.

Element tags create objects

Attributes set properties

Child nodes are used to establish relationships

Page 13: Workshop-Part2 Introduction to Xamarinsddconf.com/brands/sdd/library/Xamarin_Part_2.pdfXamarin + Xamarin.Forms With Xamarin.Forms: more code-sharing, native controls Traditional Xamarin

4/25/15

13©   2014  Xamarin.  All   rights  reserved.

public partial class MyPage : ContentPage{

public MyPage (){

InitializeComponent ();}

}

Constructor loads XML and creates UI from XAML

x:Name

<Entry x:Name="PhoneNumber" Placeholder="Number" /> .xaml

public partial class MainPage : ContentPage{

...}

.cs

field is created for you and is hidden away in another file

private Entry PhoneNumber;

Page 14: Workshop-Part2 Introduction to Xamarinsddconf.com/brands/sdd/library/Xamarin_Part_2.pdfXamarin + Xamarin.Forms With Xamarin.Forms: more code-sharing, native controls Traditional Xamarin

4/25/15

14©   2014  Xamarin.  All   rights  reserved.

UI events handler

<Button Content="Translate"   ...Clicked="OnTranslateClicked" />

.xaml

void OnTranslateClicked(object sender, EventArgs e){

Button button = (Button)sender;...

}

.cs

handler is not created for you .. must add this yourself!

Demonstration

Page 15: Workshop-Part2 Introduction to Xamarinsddconf.com/brands/sdd/library/Xamarin_Part_2.pdfXamarin + Xamarin.Forms With Xamarin.Forms: more code-sharing, native controls Traditional Xamarin

4/25/15

15©   2014  Xamarin.  All   rights  reserved.

Page 16: Workshop-Part2 Introduction to Xamarinsddconf.com/brands/sdd/library/Xamarin_Part_2.pdfXamarin + Xamarin.Forms With Xamarin.Forms: more code-sharing, native controls Traditional Xamarin

4/25/15

16©   2014  Xamarin.  All   rights  reserved.

§§§§

OR

OR

Page 17: Workshop-Part2 Introduction to Xamarinsddconf.com/brands/sdd/library/Xamarin_Part_2.pdfXamarin + Xamarin.Forms With Xamarin.Forms: more code-sharing, native controls Traditional Xamarin

4/25/15

17©   2014  Xamarin.  All   rights  reserved.

Page 18: Workshop-Part2 Introduction to Xamarinsddconf.com/brands/sdd/library/Xamarin_Part_2.pdfXamarin + Xamarin.Forms With Xamarin.Forms: more code-sharing, native controls Traditional Xamarin

4/25/15

18©   2014  Xamarin.  All   rights  reserved.

Page 19: Workshop-Part2 Introduction to Xamarinsddconf.com/brands/sdd/library/Xamarin_Part_2.pdfXamarin + Xamarin.Forms With Xamarin.Forms: more code-sharing, native controls Traditional Xamarin

4/25/15

19©   2014  Xamarin.  All   rights  reserved.

Demonstration

Page 20: Workshop-Part2 Introduction to Xamarinsddconf.com/brands/sdd/library/Xamarin_Part_2.pdfXamarin + Xamarin.Forms With Xamarin.Forms: more code-sharing, native controls Traditional Xamarin

4/25/15

20©   2014  Xamarin.  All   rights  reserved.

Basic Navigation

§ Root Page:§ NavigationPage – Gives each page an INavigation

§ Standard Navigation§ Navigation.PushAsync(page: nextPage);§ Navigation.PopAsync();

§ Modal Navigation§ Navigation.PushModalAsync(page: modalPage);§ Navigation.PopModalAsync();

Page 21: Workshop-Part2 Introduction to Xamarinsddconf.com/brands/sdd/library/Xamarin_Part_2.pdfXamarin + Xamarin.Forms With Xamarin.Forms: more code-sharing, native controls Traditional Xamarin

4/25/15

21©   2014  Xamarin.  All   rights  reserved.

Advanced Navigation

§ Editing of stack beyond push/pop§ Remove Page§ InsertPageBefore§ NavigationStack[]

§ Disable animations

InsertPageBefore

RemovePagePush/Pop

Page 22: Workshop-Part2 Introduction to Xamarinsddconf.com/brands/sdd/library/Xamarin_Part_2.pdfXamarin + Xamarin.Forms With Xamarin.Forms: more code-sharing, native controls Traditional Xamarin

4/25/15

22©   2014  Xamarin.  All   rights  reserved.

Demonstration

Summary

Page 23: Workshop-Part2 Introduction to Xamarinsddconf.com/brands/sdd/library/Xamarin_Part_2.pdfXamarin + Xamarin.Forms With Xamarin.Forms: more code-sharing, native controls Traditional Xamarin

4/25/15

23©   2014  Xamarin.  All   rights  reserved.

Get the book

Charles PetzoldXamarin

Resources

§ Documentation§ http://developer.xamarin.com/guides/cross-platform/xamarin-forms/

§ XAML Documentation§ http://developer.xamarin.com/guides/cross-platform/xamarin-

forms/xaml-for-xamarin-forms/

§ Samples§ https://github.com/xamarin/xamarin-forms-samples