StackLayout
Browse / Xamarin Development Cheat Sheet
Xamarin Development Cheat Sheet
A quick reference guide for Xamarin developers, covering essential concepts, components, and APIs for building cross-platform mobile applications with C#.
Xamarin.Forms Basics
Layouts
|
|
Arranges child views in a single line, either horizontally or vertically. |
|
Grid |
Arranges child views in rows and columns. |
|
AbsoluteLayout |
Positions child views using absolute coordinates. |
|
RelativeLayout |
Positions child views relative to each other or the parent layout. |
|
FlexLayout |
Arranges child views using flexible box layout model, similar to CSS Flexbox. |
|
ContentView |
Presents a single piece of content. Used for creating custom, reusable controls. |
Common Controls
|
Label |
Displays text. |
|
Button |
Performs an action when clicked. |
|
Entry |
Allows the user to enter single-line text. |
|
Editor |
Allows the user to enter multi-line text. |
|
Image |
Displays an image. |
|
ListView |
Displays a collection of data in a scrollable list. |
Data Binding
|
Data binding allows you to synchronize data between a UI control and a data source (e.g., a property in your view model). Example:
|
|
Use
|
Platform-Specific Code
DependencyService
|
The
|
Platform-Specific Views
|
You can create custom views for each platform to leverage platform-specific features and APIs.
|
Conditional Compilation
|
You can use conditional compilation directives to write platform-specific code within your shared codebase.
|
Navigation
Page Navigation
|
NavigationPage |
Provides navigation and history management for a stack of pages. |
|
PushAsync() |
Pushes a new page onto the navigation stack.
|
|
PopAsync() |
Removes the top page from the navigation stack.
|
|
PopToRootAsync() |
Pops all pages off the navigation stack except the root page.
|
Modal Navigation
|
PushModalAsync() |
Presents a page modally.
|
|
PopModalAsync() |
Dismisses the current modal page.
|
TabbedPage & MasterDetailPage
|
TabbedPage: Represents a multi-page interface where each child page is accessed through a tab. MasterDetailPage: Manages two panes of information: a master pane that presents data at a high level, and a detail pane that displays details about information in the master pane. |
Essentials
Xamarin.Essentials
|
Xamarin.Essentials provides APIs for accessing native device features in a cross-platform manner. Install the NuGet package to use it.
|
Common APIs
|
Connectivity |
Checks network connectivity status. |
|
Geolocation |
Retrieves the device’s current location. |
|
Preferences |
Stores and retrieves app preferences. |
|
SecureStorage |
Securely stores sensitive data. |
|
Share |
Shares text and files with other apps. |
|
VersionTracking |
Tracks app version information. |
Example Usage
|