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

Chapter 3 The Fundamentals of .NET MAUI

Windows

To receive a notification for a Windows lifecycle event, you call the

ConfigureLifecycleEvents method on the MauiAppBuilder object. You can then make use of the AddWindows method and specify the events you wish to handle and how you wish to handle them.

using Microsoft.Maui.LifecycleEvents;

namespace WidgetBoard;

public static class MauiProgram

{

public static MauiApp CreateMauiApp()

{

var builder = MauiApp.CreateBuilder(); builder

.UseMauiApp<App>()

.ConfigureLifecycleEvents(events =>

{

#if WINDOWS

events.AddWindows(lifecycle => lifecycle.OnActivated((window, args) => OnActivated(window, args)));

static void OnActivated(Microsoft. UI.Xaml.Window window, Microsoft.UI.Xaml. WindowActivatedEventArgs args)

{

// Perform your OnActivated logic

}

#endif

});

71