Last active
July 1, 2016 16:05
-
-
Save saamerm/a701011094d0123d8ce40e05d676cac3 to your computer and use it in GitHub Desktop.
This gist describes how to use the stacklayout in Xamarin Forms
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//This code was placed in the App.cs file | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using Xamarin.Forms; | |
namespace App6 | |
{ | |
public class App : Application | |
{ | |
public App() | |
{ | |
////Alternately, you can do | |
// public App() | |
//{MainPage = StackLayoutz();} | |
////and then make a new function | |
//public static Page StackLayoutz() | |
//{ | |
// return new ContentPage() | |
// { | |
// Content = new StackLayout | |
// { | |
// Spacing = 0, | |
//// and fill out the rest until the end | |
MainPage = new ContentPage() | |
{ | |
Content = new StackLayout | |
{ | |
Spacing = 0, | |
VerticalOptions = LayoutOptions.FillAndExpand, | |
Children = | |
{ | |
new Label | |
{ | |
Text = "StackLayout", | |
HorizontalOptions = LayoutOptions.Start | |
}, | |
new Label | |
{ | |
Text = "stacks its children", | |
HorizontalOptions = LayoutOptions.Center | |
}, | |
new Label | |
{ | |
Text = "vertically", | |
HorizontalOptions = LayoutOptions.End | |
}, | |
new Label | |
{ | |
Text = "by default,", | |
HorizontalOptions = LayoutOptions.Center | |
}, | |
new Label | |
{ | |
Text = "but horizontal placement", | |
HorizontalOptions = LayoutOptions.Start | |
}, | |
new Label | |
{ | |
Text = "can be controlled with", | |
HorizontalOptions = LayoutOptions.Center | |
}, | |
new Label | |
{ | |
Text = "the HorizontalOptions property.", | |
HorizontalOptions = LayoutOptions.End | |
}, | |
new Label | |
{ | |
Text = "An Expand option allows one or more children " + | |
"to occupy the an area within the remaining " + | |
"space of the StackLayout after it's been sized " + | |
"to the height of its parent.", | |
VerticalOptions = LayoutOptions.CenterAndExpand, | |
HorizontalOptions = LayoutOptions.End | |
}, | |
new StackLayout | |
{ | |
Spacing = 0, | |
Orientation = StackOrientation.Horizontal, | |
Children = | |
{ | |
new Label | |
{ | |
Text = "Stacking", | |
}, | |
new Label | |
{ | |
Text = "can also be", | |
HorizontalOptions = LayoutOptions.CenterAndExpand | |
}, | |
new Label | |
{ | |
Text = "horizontal.", | |
}, | |
} | |
} | |
} | |
} | |
}; | |
} | |
} | |
} |
Author
saamerm
commented
Jun 30, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment