为什么 OnLaunched 检查 if (rootFrame.Content == null)?

Why does OnLaunched check if (rootFrame.Content == null)?

App class 的 OnLaunched 方法中,有以下内容:

if (rootFrame.Content == null)
{
    rootFrame.Navigate(typeof(MainPage), e.Arguments);
}

为什么要检查 Content 是否为 null?显然它 是,因为 OnLaunched 方法是

"Invoked when the application is launched normally by the end user. Other entry points will be used such as when the application is launched to open a specific file." (from its summary.)

空检查的注释中给出的原因是:

"When the navigation stack isn't restored navigate to the first page,..."

但永远不会像上面那样"restored"。这在 Resuming 事件处理程序中有意义,而不是在这里。

OnLaunched 将在用户通过“开始”菜单、磁贴或任何其他通常启动应用程序的任何其他操作打开应用程序时调用,即使该应用程序已经 运行 或之前被暂停而不是终止。

请注意,在 WinRT 8.1 模板中,状态在出现在 if (rootFrame == null) 检查之前的 if (rootFrame == null) 检查中恢复, OnLaunched 处理程序中。