liveBook · Manning

ContentView

As explained in .NET MAUI in Action

ContentView is a .NET MAUI view that displays a single content object and can provide the visual basis for a templated control.

ContentView is a .NET MAUI view for displaying one content object and combining existing controls into a reusable component. It provides the visual basis for custom or templated controls, reducing repeated UI work. section 11.1

Use ContentView when a group of controls represents one repeatable piece of interaction:

  • Bundle an Entry with two Buttons to create a touch-friendly numeric stepper. section 11.1
  • Define the layout in XAML, then handle control events in code-behind. section 11.1.1
  • Expose a value property and synchronize it with typed Entry text or button changes. section 11.1.1
  • Reference the custom control from a page through an XML namespace. section 11.1.1

MildredStepper

Create a ContentView containing a three-column Grid: a minus Button, a centered Entry, and a plus Button. Change the Value property when buttons are clicked or when entered text parses as an integer, then place the control on the input page. section 11.1.1

Listing 11.1 The custom stepper layout
<?xml version="1.0" encoding="utf-8" ?>
<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="MauiStockTake.UI.Controls.MildredStepper">
    <Grid ColumnDefinitions="50,120,50">
        <Button Grid.Column="0"
                Text="-"
                Clicked="MinusButton_Clicked"
                x:Name="MinusButton"
                VerticalOptions="Center"
                HorizontalOptions="Center"
                MinimumWidthRequest="50"/>
        <Entry Grid.Column="1"
               x:Name="ValueEntry"
               FontSize="42"
               HorizontalTextAlignment="Center"
               TextChanged="ValueEntry_TextChanged"
               VerticalOptions="Center"
               HorizontalOptions="Center"/>
        <Button Grid.Column="2"
                Text="+"
                Clicked="PlusButton_Clicked"
                x:Name="PlusButton"
                VerticalOptions="Center"
                HorizontalOptions="Center"
                MinimumWidthRequest="50"/>
    </Grid>
</ContentView>

The XAML listing shows the ContentView declaration, three-control layout, event wiring, and sizing choices for the custom stepper. section 11.1.1

How .NET MAUI in Action covers it

How deep it goes
Explains component layout, event handlers, value updates, sizing, and page integration, without descending into advanced binding design.
Examples
Uses a numeric stepper combining two Buttons and an Entry for stock-count input.
What you can do after
Build it from scratch as a XAML custom control and reuse it on a .NET MAUI page.
How it connects
Connects ContentView with reusable components, templated controls, XAML, event handlers, and XML namespaces.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of .NET MAUI in Action. The section links point to the parts of the book it draws on.