Как отменить событие закрытия Microsoft.ui.xaml.window?C#

Место общения программистов C#
Anonymous
Как отменить событие закрытия Microsoft.ui.xaml.window?

Сообщение Anonymous »

Ранее я строил свою программу с использованием system.windows.window, и я мог бы отменить событие закрытия окна, переопределив событие Onclosing, чтобы окно могло быть закрыто только через меню лотка. Действительно не мог предотвратить окно, прежде чем вызвать закрытие события.
Как я могу с этим справиться?

Код: Выделить всё

public sealed partial class MainWindow : WindowEx (WindowEx : Microsoft.Ui.Xaml.Window)
{
private readonly Microsoft.UI.Dispatching.DispatcherQueue dispatcherQueue;

public MainWindow()
{
InitializeComponent();

AppWindow.SetIcon(Path.Combine(AppContext.BaseDirectory, "Assets/WindowIcon.ico"));
Content = null;
Title = "AppDisplayName".GetLocalized();

// Theme change code picked from https://github.com/microsoft/WinUI-Gallery/pull/1239
dispatcherQueue = Microsoft.UI.Dispatching.DispatcherQueue.GetForCurrentThread();
}

// this handles updating the caption button colors correctly when indows system theme is changed
// while the app is open
private void Settings_ColorValuesChanged(UISettings sender, object args)
{
This calls comes off-thread, hence we will need to dispatch it to current app's thread
dispatcherQueue.TryEnqueue(TitleBarHelper.ApplySystemThemeToCaptionButtons);
}
// ovverride OnClosing ?!
}

Я просто хочу, чтобы моя программа работала в фоновом режиме и может быть закрыта только через меню лотка.

Подробнее здесь: https://stackoverflow.com/questions/766 ... aml-window

Вернуться в «C#»