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.

  • 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

  • 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.

Last updated