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

Chapter 5 User Interface Essentials

FixedBoardPage

This is the page that will render the boards you create in the previous page. For now, you will not touch the contents of this file. Note that you should see FixedBoardPage.xaml and FixedBoardPage.xaml.cs files created.

You will also need to jump over to the MauiProgram.cs file and register this page with the Services inside the CreateMauiApp method.

builder.Services.AddTransient<FixedBoardPage>();

ViewModels

This houses your ViewModels that are the backing for both your Pages and Views. You created this folder in the previous chapter, but you need to add a number of classes. The following steps show how to add the new pages.

•\

Right-click the ViewModels folder.

•\

Select Add New Class.

•\

Click Add.

AppShellViewModel

This serves as the view model for the AppShell file that is created for you by the tooling.

namespace WidgetBoard.ViewModels;

public class AppShellViewModel : BaseViewModel

{

}

You also need to jump over to the MauiProgram.cs file and register this page with the Services inside the CreateMauiApp method.

builder.Services.AddTransient<AppShellViewModel>();

114

Chapter 5 User Interface Essentials

BoardDetailsPageViewModel

This serves as the view model for the BoardDetailsPage file you created.

namespace WidgetBoard.ViewModels;

public class BoardDetailsPageViewModel : BaseViewModel

{

}

You also need to jump over to the MauiProgram.cs file and register this page with the Services inside the CreateMauiApp method.

builder.Services.AddTransient<BoardDetailsPageViewModel>();

FixedBoardPageViewModel

This serves as the view model for the FixedBoardPage file you created.

namespace WidgetBoard.ViewModels;

public class FixedBoardPageViewModel : BaseViewModel

{

}

You also need to jump over to the MauiProgram.cs file and register this page with the Services inside the CreateMauiApp method.

builder.Services.AddTransient<FixedBoardPageViewModel>();

You should have noticed a common pattern with the creation of these files and the need to add them to the MauiProgram.cs file. This is to allow you to fully utilize the dependency injection provided by the framework, which you learned about in Chapter 3.

115