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
Padding bindable properties from the Page class.
Content property is the content property of the ContentPage class, and therefore does not need to be explicitly set from XAML.
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.