# Xamarin

{% embed url="https://dotnet.microsoft.com/en-us/apps/xamarin" %}

## Xamarin Forms

{% embed url="https://learn.microsoft.com/en-us/xamarin/xamarin-forms/" %}

## Introduction

* `Xamarin.Forms` is a framework for creating cross-platform native mobile apps with C# and XAML, by using Visual Studio.
* Xamarin.Forms isn't rendered in a webview. Instead, internally it uses the Android SDK or the iOS SDK to create native controls for native performance.
* `Xamarin.Essentials` handles many of the common needs of mobile apps that _don't_ have to do with the UI. That means with `Xamarin.Essentials` NuGet package, you can access things like the GPS, the accelerometer, and battery and network states etc.

### Pages

* Pages are the root of the UI hierarchy in `Xamarin.Forms`.
* On **iOS**, the Page is mapped to `ViewController`, on **Android**, it is mapped to somewhat like `Activity` and on **Universal Windows Platform**, it is mapped to `Page`.&#x20;
* Types
  * `ContentPage`: A content page simply displays its contents.
  * `MasterDetailPage`: This hosts drawer type navigation as well as split views. It has two key properties, `Master` and `Detail`, each of which is assigned a `ContentPage`.
  * `NavigationPage`: This adds the familiar navigation bar to the top of the screen, but more importantly manages a _navigation stack_. This stack allows the user to navigate backward to previous screens.
  * `TabbedPage`: This is the root page used for tab navigation.

### Layouts <a href="#layouts" id="layouts"></a>

![](https://1151231797-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MQAaqgCwmb83T8T0x2j%2Fuploads%2FEMeA18f13dIutf99aKBQ%2Flayouts.png?alt=media\&token=798b9e08-4b32-4fb8-b5e2-ddfbc3ffa470)

* `StackLayout` - Lays out controls in a top-to-bottom or left-to-right stack depending on an orientation property.
* `AbsoluteLayout` - Lets us set exact coordinates for controls.
* `RelativeLayout` - Lets us define relationships between multiple controls' sizes and shapes. For instance, `button1` should be 50% the size of `entry1` and should be 5 points below it.
* `Grid` - Lays out its controls according to a column and row location we set. We can define the column and row sizes as well as spans, so grid layouts don't necessarily have a "checkerboard look" to them.
* `ScrollView` - Technically, this isn't considered a layout, since it only holds one child directly but it's very important to screen layouts. By default, all the other layouts will actually try to squeeze their contents, if necessary, to fit on a single screen. But if those other layouts are put inside a ScrollView, then the screen can scroll and squeezing the contents isn't necessary.

{% embed url="https://youtube.com/playlist?list=PLdo4fOcmZ0oU10SXt2W58pu2L0v2dOW-1" %}

{% embed url="https://dotnet.microsoft.com/en-us/platform/support/policy/xamarin" %}
