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

Chapter 8 Advanced UI Concepts

Possible Ways of Achieving Your Goal

There are several ways you can go about adding in this piece of functionality. Some are better suited to different scenarios and some simply come down to a personal preference. I encourage you to understand your goal before you embark on this journey of working out which option will best suit your need. If you only wish to report a message to the user or capture a choice or even a single piece of input, then you can utilize some underlying functionality provided by .NET MAUI. The Page class provides the ability to do each of the three items discussed; it doesn’t solve your needs, but it really does have value in many applications. The Microsoft documentation provides a good set of reference examples on how to use these options at https://learn.microsoft.com/dotnet/maui/ user-interface/pop-ups.

Let’s discuss some of these options that do solve your needs and then make a decision on which you feel is the best candidate for your application.

Showing a Modal Page

So far in this book you have only considered how Shell offers the ability to navigate between ContentPages. This is the default and most common scenario. There can be times when you wish to show a page

that is blocking and will require the user to engage with it to return to the previous page. This type of page or display is referred to as modal. The scenario of showing something to the user and requiring them to engage with it could be a perfect scenario.

In order to enable this functionality in .NET MAUI, you need to set the

Shell.PresentationMode property on the ContentPage that you wish to display. For example,

222

Chapter 8 Advanced UI Concepts

<ContentPage ...

Shell.PresentationMode="Modal">

...

</ContentPage>

You can then call the Shell.Current.GoToAsync method with the routing options configured for this page and it will be presented modally instead of being navigated to.

Pro

•\

Keeps specific code contained

Con

 

•\

Complicates flow of code when handling a return result

Overlaying aView

Sometimes the most straightforward way to achieve this approach is to add another view to your page and programmatically change its visibility to give the impression you have a modal page displaying.

Pro

•\

Reduces effort of page creation

Con

 

•\

Requires specific code in calling view/view model

Showing aPopup

There is currently no explicit support in .NET MAUI for displaying popups; however, the functionality does exist on the each of the platforms that .NET MAUI runs on. You can go to the lengths of implementing your own ability to display a popup but it would be rather involved. Instead, the .NET MAUI Community Toolkit provides a Popup class that makes it straightforward for you to display a popup in your application.

223