Docsity
Docsity

Prepare-se para as provas
Prepare-se para as provas

Estude fácil! Tem muito documento disponível na Docsity


Ganhe pontos para baixar
Ganhe pontos para baixar

Ganhe pontos ajudando outros esrudantes ou compre um plano Premium


Guias e Dicas
Guias e Dicas


Manipulação de Componentes em Xamarin.Forms, Resumos de Matemática

Neste documento, aprenderá a criar e manipular diferentes componentes em xamarin.forms usando c#. O documento aborda a criação de labels, botões, entrada de texto e outros elementos básicos, além de expor como criar páginas, manipular eventos e utilizar layouts. O documento também inclui exemplos de código para ajudar no entendimento.

Tipologia: Resumos

2021

Compartilhado em 26/08/2021

DalioDora
DalioDora 🇧🇷

1 documento

1 / 181

Toggle sidebar

Esta página não é visível na pré-visualização

Não perca as partes importantes!

bg1
Xamarin.Forms
Notes for Professionals
Xamarin
.Forms
Notes for Professionals
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
100+ pages
of professional hints and tricks
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Pré-visualização parcial do texto

Baixe Manipulação de Componentes em Xamarin.Forms e outras Resumos em PDF para Matemática, somente na Docsity!

Xamarin.Forms Notes for Professionals

Xamarin

.Forms

Notes for Professionals

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

100+ pages

of professional hints and tricks

Contents

  • About
  • Chapter 1: Getting started with Xamarin.Forms
    • Section 1.1: Installation (Visual Studio)
    • Section 1.2: Hello World Xamarin Forms: Visual Studio
  • Chapter 2: Why Xamarin Forms and When to use Xamarin Forms
    • Section 2.1: Why Xamarin Forms and When to use Xamarin Forms
  • Chapter 3: Xamarin Forms Layouts
    • Section 3.1: AbsoluteLayout
    • Section 3.2: Grid
    • Section 3.3: ContentPresenter
    • Section 3.4: ContentView
    • Section 3.5: ScrollView
    • Section 3.6: Frame
    • Section 3.7: TemplatedView
    • Section 3.8: RelativeLayout
    • Section 3.9: StackLayout
  • Chapter 4: Xamarin Relative Layout
    • Section 4.1: Box after box
    • Section 4.2: Page with an simple label on the middle
  • Chapter 5: Navigation in Xamarin.Forms
    • Section 5.1: NavigationPage flow with XAML
    • Section 5.2: NavigationPage flow
    • Section 5.3: Master Detail Navigation
    • Section 5.4: Using INavigation from view model
    • Section 5.5: Master Detail Root Page
    • Section 5.6: Hierarchical navigation with XAML
    • Section 5.7: Modal navigation with XAML
  • Chapter 6: Xamarin.Forms Page
    • Section 6.1: TabbedPage
    • Section 6.2: ContentPage
    • Section 6.3: MasterDetailPage
  • Chapter 7: Xamarin.Forms Cells
    • Section 7.1: EntryCell
    • Section 7.2: SwitchCell
    • Section 7.3: TextCell
    • Section 7.4: ImageCell
    • Section 7.5: ViewCell
  • Chapter 8: Xamarin.Forms Views
    • Section 8.1: Button
    • Section 8.2: DatePicker
    • Section 8.3: Entry
    • Section 8.4: Editor
    • Section 8.5: Image
    • Section 8.6: Label
  • Chapter 9: Using ListViews
    • Section 9.1: Pull to Refresh in XAML and Code behind
  • Chapter 10: Display Alert
    • Section 10.1: DisplayAlert
    • Section 10.2: Alert Example with only one button and action
  • Chapter 11: Accessing native features with DependencyService
    • Section 11.1: Implementing text-to-speech
    • Section 11.2: Getting Application and Device OS Version Numbers - Android & iOS - PCL
  • Chapter 12: DependencyService
    • Section 12.1: Android implementation
    • Section 12.2: Interface
    • Section 12.3: iOS implementation
    • Section 12.4: Shared code
  • Chapter 13: Custom Renderers
    • Section 13.1: Accessing renderer from a native project
    • Section 13.2: Rounded label with a custom renderer for Frame (PCL & iOS parts)
    • Section 13.3: Custom renderer for ListView
    • Section 13.4: Custom Renderer for BoxView
    • Section 13.5: Rounded BoxView with selectable background color
  • Chapter 14: Caching
    • Section 14.1: Caching using Akavache
  • Chapter 15: Gestures
    • Section 15.1: Make an Image tappable by adding a TapGestureRecognizer
    • Section 15.2: Gesture Event
    • Section 15.3: Zoom an Image with the Pinch gesture
    • Section 15.4: Show all of the zoomed Image content with the PanGestureRecognizer
    • Section 15.5: Tap Gesture
    • Section 15.6: Place a pin where the user touched the screen with MR.Gestures
  • Chapter 16: Data Binding
    • Section 16.1: Basic Binding to ViewModel
  • Chapter 17: Working with Maps
    • Section 17.1: Adding a map in Xamarin.Forms (Xamarin Studio)
  • Chapter 18: Custom Fonts in Styles
    • Section 18.1: Accessing custom Fonts in Syles
  • Chapter 19: Push Notifications
    • Section 19.1: Push notifications for Android with Azure
    • Section 19.2: Push notifications for iOS with Azure
    • Section 19.3: iOS Example
  • Chapter 20: Eects
    • Section 20.1: Adding platform specific Eect for an Entry control
  • Chapter 21: Triggers & Behaviours
    • Section 21.1: Xamarin Forms Trigger Example
    • Section 21.2: Multi Triggers
  • Chapter 22: AppSettings Reader in Xamarin.Forms
    • Section 22.1: Reading app.config file in a Xamarin.Forms Xaml project
  • Chapter 23: Creating custom controls
    • Section 23.1: Label with bindable collection of Spans
    • Section 23.2: Implementing a CheckBox Control
    • Section 23.3: Create an Xamarin Forms custom input control (no native required)
    • Section 23.4: Creating a custom Entry control with a MaxLength property
    • Section 23.5: Creating custom Button
  • Chapter 24: Working with local databases
    • Section 24.1: Using SQLite.NET in a Shared Project
    • Section 24.2: Working with local databases using xamarin.forms in visual studio
  • Chapter 25: CarouselView - Pre-release version
    • Section 25.1: Import CarouselView
    • Section 25.2: Import CarouselView into a XAML Page
  • Chapter 26: Exception handling
    • Section 26.1: One way to report about exceptions on iOS
  • Chapter 27: SQL Database and API in Xamarin Forms.
    • Section 27.1: Create API using SQL database and implement in Xamarin forms,
  • Chapter 28: Contact Picker - Xamarin Forms (Android and iOS)
    • Section 28.1: contact_picker.cs
    • Section 28.2: MyPage.cs
    • Section 28.3: ChooseContactPicker.cs
    • Section 28.4: ChooseContactActivity.cs
    • Section 28.5: MainActivity.cs
    • Section 28.6: ChooseContactRenderer.cs
  • Chapter 29: Xamarin Plugin
    • Section 29.1: Media Plugin
    • Section 29.2: Share Plugin
    • Section 29.3: ExternalMaps
    • Section 29.4: Geolocator Plugin
    • Section 29.5: Messaging Plugin
    • Section 29.6: Permissions Plugin
  • Chapter 30: OAuth2
    • Section 30.1: Authentication by using Plugin
  • Chapter 31: MessagingCenter
    • Section 31.1: Simple example
    • Section 31.2: Passing arguments
    • Section 31.3: Unsubscribing
  • Chapter 32: Generic Xamarin.Forms app lifecycle? Platform-dependant! - it Section 32.1: Xamarin.Forms lifecycle is not the actual app lifecycle but a cross-platform representation of
  • Chapter 33: Platform-specific behaviour
    • Section 33.1: Removing icon in navigation header in Anroid
    • Section 33.2: Make label's font size smaller in iOS
  • Chapter 34: Platform specific visual adjustments
    • Section 34.1: Idiom adjustments
    • Section 34.2: Platform adjustments
    • Section 34.3: Using styles
    • Section 34.4: Using custom views
  • Chapter 35: Dependency Services
    • Section 35.1: Access Camera and Gallery
  • Chapter 36: Unit Testing
    • Section 36.1: Testing the view models
  • Chapter 37: BDD Unit Testing in Xamarin.Forms
    • Section 37.1: Simple Specflow to test commands and navigation with NUnit Test Runner
    • Section 37.2: Advanced Usage for MVVM
  • Credits
  • You may also like

Chapter 1: Getting started with

Xamarin.Forms

Version Release Date 3.0.0 2018-05- 2.5.0 2017-11- 2.4.0 2017-09- 2.3.1 2016-08- 2.3.0-hotfix1 2016-06- 2.3.0 2016-06- 2.2.0-hotfix1 2016-05- 2.2.0 2016-04- 2.1.0 2016-03- 2.0.1 2016-01- 2.0.0 2015-11- 1.5.1 2016-10- 1.5.0 2016-09- 1.4.4 2015-07- 1.4.3 2015-06- 1.4.2 2015-04- 1.4.1 2015-03- 1.4.0 2015-03- 1.3.5 2015-03- 1.3.4 2015-02- 1.3.3 2015-02- 1.3.2 2015-02- 1.3.1 2015-01- 1.3.0 2014-12- 1.2.3 2014-10- 1.2.2 2014-07- 1.2.1 2014-07- 1.2.0 2014-07- 1.1.1 2014-06- 1.1.0 2014-06- 1.0.1 2014-06-

Section 1.1: Installation (Visual Studio)

Xamarin.Forms is a cross-platform natively backed UI toolkit abstraction that allows developers to easily create user interfaces that can be shared across Android, iOS, Windows, and Windows Phone. The user interfaces are rendered using the native controls of the target platform, allowing Xamarin.Forms applications to retain the appropriate look and feel for each platform.

Xamarin Plugin for Visual Studio

To get started with Xamarin.Forms for Visual Studio you need to have the Xamarin plugin itself. The easiest way to have it installed is to download and install the latest Visual Studio.

If you already have the latest Visual Studio installed, go to Control Panel > Programs and Features, right click on Visual Studio, and click Change. When the installer opens, click on Modify, and select the cross-platform mobile development tools:

You can also select to install the Android SDK:

Uncheck it if you already have the SDK installed. You will be able to setup Xamarin to use existing Android SDK later.

Xamarin.Forms

Xamarin.Forms is a set of libraries for your Portable Class library and native assemblies. The Xamarin.Forms library itself is available as a NuGet package. To add it to your project just use the regular Install-Package command of the Package Manager Console:

Install-Package Xamarin.Forms

for all of your initial assemblies (for example MyProject, MyProject.Droid and MyProject.iOS).

The easiest way to get started with Xamarin.Forms is to create an empty project in Visual Studio:

Step 2: Investigating the sample

Having created the solution, a sample application will be ready to be deployed. Open the App.cs located in the root of the portable project and investigate the code. As seen below, the Contents of the sample is a StackLayout which contains a Label:

using Xamarin.Forms;

namespace Hello_World { public class App : Application { public App() { // The root page of your application MainPage = new ContentPage { Content = new StackLayout { VerticalOptions = LayoutOptions.Center, Children = { new Label { HorizontalTextAlignment = TextAlignment.Center, Text = "Welcome to Xamarin Forms!" } } } }; } protected override void OnStart()

{ // Handle when your app starts } protected override void OnSleep() { // Handle when your app sleeps } protected override void OnResume() { // Handle when your app resumes } } }

Step 3: Launching the application

Now simply right-click the project you want to start (HelloWorld.Droid or HelloWorld.iOS) and click Set as StartUp Project. Then, in the Visual Studio toolbar, click the Start button (the green triangular button that resembles a Play button) to launch the application on the targeted simulator/emulator.

Chapter 3: Xamarin Forms Layouts

Section 3.1: AbsoluteLayout

AbsoluteLayout positions and sizes child elements proportional to its own size and position or by absolute values. Child views may be positioned and sized using proportional values or static values, and proportional and static values can be mixed.

A definition of an AbsoluteLayout in XAML looks like this:

<Label Text="I'm centered on iPhone 4 but no other device" AbsoluteLayout.LayoutBounds="115,150,100,100" LineBreakMode="WordWrap" /> <Label Text="I'm bottom center on every device." AbsoluteLayout.LayoutBounds=".5,1,.5,.1" AbsoluteLayout.LayoutFlags="All" LineBreakMode="WordWrap" /> <BoxView Color="Olive" AbsoluteLayout.LayoutBounds="1,.5, 25, 100" AbsoluteLayout.LayoutFlags="PositionProportional" /> <BoxView Color="Red" AbsoluteLayout.LayoutBounds="0,.5,25,100" AbsoluteLayout.LayoutFlags="PositionProportional" /> <BoxView Color="Blue" AbsoluteLayout.LayoutBounds=".5,0,100,25" AbsoluteLayout.LayoutFlags="PositionProportional" /> <BoxView Color="Blue" AbsoluteLayout.LayoutBounds=".5,0,1,25" AbsoluteLayout.LayoutFlags="PositionProportional, WidthProportional" />

The same layout would look like this in code:

Title = "Absolute Layout Exploration - Code"; var layout = new AbsoluteLayout();

var centerLabel = new Label { Text = "I'm centered on iPhone 4 but no other device.", LineBreakMode = LineBreakMode.WordWrap};

AbsoluteLayout.SetLayoutBounds (centerLabel, new Rectangle (115, 159, 100, 100));

// No need to set layout flags, absolute positioning is the default

var bottomLabel = new Label { Text = "I'm bottom center on every device.", LineBreakMode = LineBreakMode.WordWrap }; AbsoluteLayout.SetLayoutBounds (bottomLabel, new Rectangle (.5, 1, .5, .1)); AbsoluteLayout.SetLayoutFlags (bottomLabel, AbsoluteLayoutFlags.All);

var rightBox = new BoxView{ Color = Color.Olive }; AbsoluteLayout.SetLayoutBounds (rightBox, new Rectangle (1, .5, 25, 100)); AbsoluteLayout.SetLayoutFlags (rightBox, AbsoluteLayoutFlags.PositionProportional);

var leftBox = new BoxView{ Color = Color.Red }; AbsoluteLayout.SetLayoutBounds (leftBox, new Rectangle (0, .5, 25, 100)); AbsoluteLayout.SetLayoutFlags (leftBox, AbsoluteLayoutFlags.PositionProportional);

var topBox = new BoxView{ Color = Color.Blue }; AbsoluteLayout.SetLayoutBounds (topBox, new Rectangle (.5, 0, 100, 25)); AbsoluteLayout.SetLayoutFlags (topBox, AbsoluteLayoutFlags.PositionProportional);

var twoFlagsBox = new BoxView{ Color = Color.Blue }; AbsoluteLayout.SetLayoutBounds (topBox, new Rectangle (.5, 0, 1, 25)); AbsoluteLayout.SetLayoutFlags (topBox, AbsoluteLayoutFlags.PositionProportional | AbsoluteLayout.WidthProportional);

layout.Children.Add (bottomLabel); layout.Children.Add (centerLabel); layout.Children.Add (rightBox); layout.Children.Add (leftBox); layout.Children.Add (topBox);

The AbsoluteLayout control in Xamarin.Forms allows you to specify where exactly on the screen you want the child elements to appear, as well as their size and shape (bounds).

There are a few different ways to set the bounds of the child elements based on the AbsoluteLayoutFlags enumeration that are used during this process. The AbsoluteLayoutFlags enumeration contains the following values:

All : All dimensions are proportional. HeightProportional : Height is proportional to the layout. None : No interpretation is done. PositionProportional : Combines XProportional and YProportional. SizeProportional : Combines WidthProportional and HeightProportional. WidthProportional : Width is proportional to the layout. XProportional : X property is proportional to the layout. YProportional : Y property is proportional to the layout.

The process of working with the layout of the AbsoluteLayout container may seem a little counterintuitive at first, but with a little use it will become familiar. Once you have created your child elements, to set them at an absolute position within the container you will need to follow three steps. You will want to set the flags assigned to the elements using the AbsoluteLayout.SetLayoutFlags() method. You will also want to use the AbsoluteLayout.SetLayoutBounds() method to give the elements their bounds. Finally, you will want to add the child elements to the Children collection. Since Xamarin.Forms is an abstraction layer between Xamarin and the device-specific implementations, the positional values can be independent of the device pixels. This is where the layout flags mentioned previously come into play. You can choose how the layout process of the Xamarin.Forms controls should interpret the values you define.

<--DEFINITIONS...--! >

<ContentView Grid.Row="0" Grid.Column="0" /> <ContentView Grid.Row="1" Grid.Column="0" /> <ContentView Grid.Row="2" Grid.Column="0" />

<ContentView Grid.Row="0" Grid.Column="1" /> <ContentView Grid.Row="1" Grid.Column="1" /> <ContentView Grid.Row="2" Grid.Column="1" />

In C# code:

var grid = new Grid(); //DEFINITIONS... var topLeft = new Label { Text = "Top Left" }; var topRight = new Label { Text = "Top Right" }; var bottomLeft = new Label { Text = "Bottom Left" }; var bottomRight = new Label { Text = "Bottom Right" }; grid.Children.Add(topLeft, 0, 0); grid.Children.Add(topRight, 0, 1); grid.Children.Add(bottomLeft, 1, 0); grid.Children.Add(bottomRight, 1, 1);

For Height and Width a number of units are available.

Auto – automatically sizes to fit content in the row or column. Specified as GridUnitType.Auto in C# or as Auto in XAML. Proportional – sizes columns and rows as a proportion of the remaining space. Specified as a value and GridUnitType.Star in C# and as #* in XAML, with # being your desired value. Specifying one row/column with

  • will cause it to fill the available space. Absolute – sizes columns and rows with specific, fixed height and width values. Specified as a value and GridUnitType.Absolute in C# and as # in XAML, with # being your desired value.

Note: The width values for columns are set as Auto by default in Xamarin.Forms, which means that the width is determined from the size of the children. Note that this differs from the implementation of XAML on Microsoft platforms, where the default width is *, which will fill the available space.

Section 3.3: ContentPresenter

A layout manager for templated views. Used within a ControlTemplate to mark where the content to be presented appears.

Section 3.4: ContentView

An element with a single content. ContentView has very little use of its own. Its purpose is to serve as a base class for user-defined compound views.

XAML

<Label Text="Hi, I'm a simple Label inside of a simple ContentView" HorizontalOptions="Center" VerticalOptions="Center" />

Code

stack.Children.Add(new Entry());

Section 3.6: Frame

An element containing a single child, with some framing options. Frame have a default Xamarin.Forms.Layout.Padding of 20.

XAML

<Label Text="I've been framed!" HorizontalOptions="Center" VerticalOptions="Center" />

Code

var frameView = new Frame { Content = new Label { Text = "I've been framed!", HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Center }, OutlineColor = Color.Red };

Section 3.7: TemplatedView

An element that displays content with a control template, and the base class for ContentView.

Section 3.8: RelativeLayout

A Layout that uses Constraints to layout its children.

RelativeLayout is used to position and size views relative to properties of the layout or sibling views. Unlike AbsoluteLayout, RelativeLayout does not have the concept of the moving anchor and does not have facilities for positioning elements relative to the bottom or right edges of the layout. RelativeLayout does support positioning elements outside of its own bounds.

A RelativeLayout in XAML, is like this:

<BoxView Color="Red" x:Name="redBox" RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height,Factor=.15,Constant=0}"