【发布时间】:2021-10-26 09:51:29
【问题描述】:
我需要获取默认打开的 AppWindow 实例。怎么做?我需要它来跟踪窗口关闭事件。
也许我可以使用 Windows.UI 做到这一点?
【问题讨论】:
标签: uwp
我需要获取默认打开的 AppWindow 实例。怎么做?我需要它来跟踪窗口关闭事件。
也许我可以使用 Windows.UI 做到这一点?
【问题讨论】:
标签: uwp
有一个静态的Window.Current 属性,您可以使用它来获取对当前线程窗口的引用。
UWP 中没有可用的Closing 事件,因此如果您想在应用关闭时处理事件,您需要confirmAppClose 功能:
【讨论】:
如何获取主 AppWindow 的实例?
如果您提到AppWindow 用于显示多个视图,您可以参考此document。
在本文档中,它告诉跟踪 AppWindow 实例 three ways 简单跟踪、在其托管内容中跟踪 AppWindow 实例以及使用 UIContext 跟踪应用程序窗口。
而AppWindow包含Closed事件,需要在窗口关闭时释放资源。
appWindow.Closed += delegate
{
appWindowContentFrame.Content = null;
appWindow = null;
};
【讨论】: