ContentPage
The .NET Multi-platform App UI (.NET MAUI) ContentPage
displays a single view, which is often a layout such as as Grid
or StackLayout
, and is the most common page type.
Important
.NET Multi-platform App UI (.NET MAUI) is currently in preview. This content relates to a pre-release product that may be substantially modified before it's released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
ContentPage
defines a Content
property, of type View
, which defines the view that represents the page's content. This property is backed by a BindableProperty
object, which means that it can be the target of data bindings, and styled. In addition, ContentPage
inherits Title
, IconImageSource
, BackgroundImageSource
, IsBusy
, and Padding
bindable properties from the Page
class.
Note
The Content
property is the content property of the ContentPage
class, and therefore does not need to be explicitly set from XAML.
.NET MAUI apps typically contain multiple pages that derive from ContentPage
, and navigation between these pages can be performed. For more information about page navigation, see NavigationPage.
A ContentPage
can be templated with a control template. For more information, see Control templates.
Create a ContentPage
To add a ContentPage
to a .NET MAUI app:
In Solution Explorer right-click on your project or folder in your project, and select New Item....
In the Add New Item dialog, expand Installed > C# Items, select .NET MAUI, and select the .NET MAUI ContentPage (XAML) item template, enter a suitable page name, and click the Add button:
Visual Studio then creates a new ContentPage
-derived page, which will be similar to the following example:
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MyMauiApp.MyPage"
Title="MyPage"
BackgroundColor="White">
<StackLayout>
<Label Text="Welcome to .NET MAUI!"
VerticalOptions="Center"
HorizontalOptions="Center" />
<!-- Other views go here -->
</StackLayout>
</ContentPage>
The child of a ContentPage
is typically a layout, such as Grid
or StackLayout
, with the layout typically containing multiple views. However, the child of the ContentPage
can be a view that displays a collection, such as CollectionView
.
Note
The value of the Title
property will be shown on the navigation bar, when the app performs navigation using a NavigationPage
. For more information, see NavigationPage.
Feedback
Submit and view feedback for