Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
lawrence_shaun_introducing_net_maui_build_and_deploy_crosspl.pdf
Скачиваний:
46
Добавлен:
26.06.2023
Размер:
5.15 Mб
Скачать

Chapter 4 An Architecture to Suit You

View

The View defines the layout and appearance of the application. It is what the user will see and interact with. In .NET MAUI, a View is typically written in XAML where possible, but there will be occasions when logic in the code-behind will need to be written. You will learn this later in this chapter; you don’t have to use XAML at all so if you don’t feel XAML is right for you, fear not.

A View in .NET MAUI is typically a ContentPage or an implementation that will inherit from ContentPage or ContentView. You use a ContentPage if you want to render a full page in your application (basically a view that will fill the application). You use a ContentView for something smaller (like a widget!). For your implementation you will be inheriting from a ContentView.

I discussed in Chapter 2 that the majority of XAML files come with an associated C# file. A XAML-based view is no exception to this rule. With this in mind, let’s take a look at the contents you need to place in each of the files.

XAML

<?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" xmlns:viewmodels="clr-namespace:WidgetBoard. ViewModels" x:Class="WidgetBoard.ClockWidget">

<ContentView.BindingContext> <viewmodels:ClockWidgetViewModel />

</ContentView.BindingContext>

<Label Text="{Binding Time}"

79