Professional Documents
Culture Documents
Forms
Las páginas de Xamarin.Forms representan pantallas de aplicaciones móviles
multiplataforma.
Todos los tipos de página que se describen a continuación se derivan de la clase de
Xamarin.Forms. Estos elementos visuales ocupan toda o la mayor parte de la
pantalla. Un objeto Page representa un ViewController en iOS y una Page en la
plataforma universal de Windows. En Android, cada página ocupa la pantalla como
una Activity , pero las páginas de Xamarin.Forms no son objetos de Activity .
ContentPage
MasterDetailPage
using System;
using Xamarin.Forms;
namespace FormsGallery.CodeExamples
{
class MasterDetailPageDemoPage : MasterDetailPage
{
public MasterDetailPageDemoPage ()
{
Title = "MasterDetailPage Demo";
detailPage.Content.BackgroundColor = Color.Transparent;
detailPage.Content.GestureRecognizers.Add (tap);
}
NavigationPage
namespace FormsGallery.CodeExamples
{
// Although this page is actually a ContentPage, it can
// function as a NavigationPage because the HomePage
// is launched as an ApplicationPage in App.
class NavigationPageDemoPage : ContentPage
{
public NavigationPageDemoPage()
{
Label header = new Label
{
Text = "NavigationPage",
FontSize = 40,
FontAttributes = FontAttributes.Bold,
HorizontalOptions = LayoutOptions.Center
};
TabbedPage
using System;
using Xamarin.Forms;
namespace FormsGallery.CodeExamples
{
class TabbedPageDemoPage : TabbedPage
{
public TabbedPageDemoPage()
{
Title = "TabbedPage Demo";
CarouselPage
using System;
using Xamarin.Forms;
namespace FormsGallery.CodeExamples
{
class CarouselPageDemoPage : CarouselPage
{
public CarouselPageDemoPage()
{
Title = "CarouselPage Demo";
ItemsSource = new NamedColor[]
{
new NamedColor("Red", Color.Red),
new NamedColor("Yellow", Color.Yellow),
new NamedColor("Green", Color.Green),
new NamedColor("Aqua", Color.Aqua),
new NamedColor("Blue", Color.Blue),
new NamedColor("Purple", Color.Purple)
};
TemplatedPage
ContentView
ContentView contiene un único elemento secundario que se establece con la propiedad
Content . La propiedad de Content se puede establecer en cualquier Derivado de View ,
incluyendo otros derivados de Layout . ContentView se usa principalmente como elemento
estructural y sirve como una clase base para Frame .
using System;
using Xamarin.Forms;
namespace FormsGallery.CodeExamples
{
class ContentViewDemoPage : ContentPage
{
public ContentViewDemoPage()
{
Label header = new Label
{
Text = "ContentView",
FontSize = 50,
FontAttributes = FontAttributes.Bold,
HorizontalOptions = LayoutOptions.Center
};
Frame
La clase Frame deriva de ContentView y muestra un marco rectangular alrededor de su hijo.
Frame tiene un valor de Padding predeterminado de 20, y también define las OutlineColor ,
CornerRadius y HasShadow .
using System;
using Xamarin.Forms;
namespace FormsGallery.CodeExamples
{
class FrameDemoPage : ContentPage
{
public FrameDemoPage()
{
Label header = new Label
{
Text = "Frame",
FontSize = 50,
FontAttributes = FontAttributes.Bold,
HorizontalOptions = LayoutOptions.Center
};
ScrollView
ScrollView es capaz de desplazar sus contenidos. Establezca la propiedad Content en una
vista o diseño demasiado grande para que quepa en la pantalla. (El contenido de un
ScrollView es muy a menudo un StackLayout .) Establezca la propiedad Orientation para
indicar si el desplazamiento debe ser vertical, horizontal o ambos.
using System;
using Xamarin.Forms;
namespace FormsGallery.CodeExamples
{
class ScrollViewDemoPage : ContentPage
{
public ScrollViewDemoPage()
{
Label header = new Label
{
Text = "ScrollView",
FontSize = 50,
FontAttributes = FontAttributes.Bold,
HorizontalOptions = LayoutOptions.Center
};
FontSize = Device.GetNamedSize(NamedSize.Large,
typeof(Label)),
}
};
TemplatedView muestra el contenido con una plantilla de control y es la clase base para
ContentView .
ContentPresenter
StackLayout
using System;
using Xamarin.Forms;
namespace FormsGallery.CodeExamples
{
class StackLayoutDemoPage : ContentPage
{
public StackLayoutDemoPage()
{
Label header = new Label
{
Text = "StackLayout",
FontSize = 50,
FontAttributes = FontAttributes.Bold,
HorizontalOptions = LayoutOptions.Center
};
Grid
Grid coloca sus elementos secundarios en una cuadrícula de filas y columnas. La posición
de un niño se indica mediante las propiedades adjuntas Row , Column , Row y Column
ColumnSpan .
using System;
using Xamarin.Forms;
namespace FormsGallery.CodeExamples
{
class GridDemoPage : ContentPage
{
public GridDemoPage ()
{
Grid grid = new Grid
{
VerticalOptions = LayoutOptions.FillAndExpand,
Margin = new Thickness(10),
RowDefinitions =
{
new RowDefinition { Height = GridLength.Auto },
new RowDefinition { Height = GridLength.Auto },
new RowDefinition { Height = new GridLength (1,
GridUnitType.Star) },
new RowDefinition { Height = new GridLength (100,
GridUnitType.Absolute) }
},
ColumnDefinitions =
{
new ColumnDefinition { Width = GridLength.Auto },
new ColumnDefinition { Width = new GridLength (1,
GridUnitType.Star) },
new ColumnDefinition { Width = new GridLength (100,
GridUnitType.Absolute) }
}
};
AbsoluteLayout
RelativeLayout
RelativeLayout coloca elementos secundarios en relación con RelativeLayout sí o con sus
hermanos. La posición de un niño se indica mediante las propiedades adjuntas que se
establecen en objetos de tipo Constraint y BoundsConstraint .
using System;
using Xamarin.Forms;
namespace FormsGallery.CodeExamples
{
class RelativeLayoutDemoPage : ContentPage
{
public RelativeLayoutDemoPage ()
{
Label header = new Label
{
Text = "RelativeLayout",
FontSize = 40,
FontAttributes = FontAttributes.Bold,
HorizontalTextAlignment = TextAlignment.Center
};
// Four BoxView's
relativeLayout.Children.Add (
new BoxView { Color = Color.Red },
Constraint.Constant (0),
Constraint.Constant (0));
relativeLayout.Children.Add (
new BoxView { Color = Color.Green },
Constraint.RelativeToParent ((parent) => {
return parent.Width - 40;
}),
Constraint.Constant (0));
relativeLayout.Children.Add (
new BoxView { Color = Color.Blue },
Constraint.Constant (0),
Constraint.RelativeToParent ((parent) => {
return parent.Height - 40;
}));
relativeLayout.Children.Add (
new BoxView { Color = Color.Yellow },
Constraint.RelativeToParent ((parent) => {
return parent.Width - 40;
}),
Constraint.RelativeToParent ((parent) => {
return parent.Height - 40;
}));
Content = grid;
}
}
}
FlexLayout
using System;
using System.Collections.Generic;
using Xamarin.Forms;
namespace FormsGallery.CodeExamples
{
public class FlexLayoutDemoPage : ContentPage
{
class DataItem
{
public string Header { set; get; }
public FlexLayoutDemoPage ()
{
FlexLayout flexLayout = new FlexLayout();
var x = ImageSource.FromResource("");
FlexLayout.SetOrder(image, -1);
FlexLayout.SetAlignSelf(image, FlexAlignSelf.Center);
itemFlexLayout.Children.Add(image);
itemFlexLayout.Children.Add(new Button
{
Text = "LEARN MORE",
FontSize = Device.GetNamedSize(NamedSize.Large,
typeof(Button)),
TextColor = Color.White,
BackgroundColor = Color.Green,
CornerRadius = 20
});
flexLayout.Children.Add(new Frame
{
WidthRequest = 300,
HeightRequest = 480,
BackgroundColor = Color.LightYellow,
BorderColor = Color.Blue,
Margin = new Thickness(10),
CornerRadius = 15,
Content = itemFlexLayout
});
}