La capa StackLayout omite los limites de sus elementos hijo, es por esto que el desarrollador no debe establecer los limites en estos elementos.
El siguiente ejemplo muestra como crear una nueva capa StackLayout con elementos subyacentes que exploran algunos de los comportamientos de la capa StackLayout.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
StackLayout stackLayout = new StackLayout { Spacing = 0, VerticalOptions = LayoutOptions.FillAndExpand, Children = { new Label { Text = "StackLayout", HorizontalOptions = LayoutOptions.Start }, new Label { Text = "Capas subyacentes", HorizontalOptions = LayoutOptions.Center }, new Label { Text = "verticalmente", HorizontalOptions = LayoutOptions.End }, new Label { Text = "por defecto,", HorizontalOptions = LayoutOptions.Center }, new Label { Text = "pero con posicionamiento horizontal", HorizontalOptions = LayoutOptions.Start }, new Label { Text = "puede ser controlado con", HorizontalOptions = LayoutOptions.Center }, new Label { Text = "la propiedad HorizontalOptions.", HorizontalOptions = LayoutOptions.End }, new Label { Text = "La opcion Expand permite uno o mas hijos " + "para ocupar el area en el espacio " + "restante de la capa StackLayout despues " + "es escalada al tamaño de su padre.", VerticalOptions = LayoutOptions.CenterAndExpand, HorizontalOptions = LayoutOptions.End }, new StackLayout { Spacing = 0, Orientation = StackOrientation.Horizontal, Children = { new Label { Text = "Stacking", }, new Label { Text = "puede ser", HorizontalOptions = LayoutOptions.CenterAndExpand }, new Label { Text = "horizontal.", }, } } } }; |
Si pegamos el código anterior en un proyecto Xamarin.Forms en App.cs y compilamos, obtendremos el siguiente resultado.
1 2 3 4 5 6 7 8 9 10 |
public App() { StackLayout stackLayout = new StackLayout {...} var content = new ContentPage { Title = "Ejemplo StackLayout", Content = stackLayout }; MainPage = new NavigationPage(content); } |