Xamarin.Forms Guides | Samples

Xamarin.Forms.ContentPage Class

A Page that displays a single view.

See Also: ContentPage

Syntax

[Xamarin.Forms.ContentProperty("Content")]
public class ContentPage : TemplatedPage

Remarks

This is a Page displaying a single View, often a container like a StackLayout or ScrollView.

The example below is taken from he App.cs file that is contained in the default "Hello, Forms!" app. It uses a ContentPage to display a label, which is a typical, though basic, use of the ContentPage class.

C# Example

using System;
using Xamarin.Forms;

namespace ContentPageExample
{
    public class App
    {
        public static Page GetMainPage ()
        {    
            return new ContentPage { 
                Content = new Label {
                    Text = "Hello, Forms!",
                    VerticalOptions = LayoutOptions.CenterAndExpand,
                    HorizontalOptions = LayoutOptions.CenterAndExpand,
                },
            };
        }
    }
}

The FormsGallery sample, which can be found on the Sample Applications page, has a ContentPageDemoPage.cs file. This file contains a longer and more complicated example.

XAML for Xamarin.Forms supports the following property for the ContentPage class:

PropertyValue
Content

A list of View objects that represent the visual content of the ContentPage. This tag can be omitted, and the contents listed directly.

A ContentPage tag can be the root element of a XAML document.

Requirements

Namespace: Xamarin.Forms
Assembly: Xamarin.Forms.Core (in Xamarin.Forms.Core.dll)
Assembly Versions: 1.0.0.0, 1.1.0.0, 1.2.0.0, 1.3.0.0, 1.4.0.0, 1.5.0.0, 2.0.0.0

The members of Xamarin.Forms.ContentPage are listed below.

See Also: TemplatedPage

Public Constructors

Initializes a new ContentPage instance.

Public Fields

static readonly
ContentPropertyBindableProperty. Backing store for the ContentPage.Content property.

Public Properties

ContentView. Gets or sets the view that contains the content of the Page.

Protected Methods

override
OnBindingContextChanged()
Method that is called when the binding context changes.