问题描述
我的应用程序在 Windows 应用商店中一团糟.我添加了一个基本页面,它添加了通用类,例如 LayoutAwarePage.
I have a Windows Store mess around app. I added a Basic Page and it added the Common classes, such as LayoutAwarePage.
但是 Page.OnNavigatedTo 在应用程序启动时不会被调用.MSDN 文档说:
But Page.OnNavigatedTo doesn't get called when an app starts. The MSDN doc says:
当页面被加载并成为一个页面的当前源时调用父框架
在发布期间发生的事情.我在没有调用 LoadState 时发现了这一点.
Which happens during launch. I discovered this when LoadState wasn't being called.
Rick Barraza 在他的演示中使用了 OnNavigatedTo 调用的 LoadState:
Rick Barraza uses LoadState, which is called by OnNavigatedTo, in his demo:
我知道有些东西坏了,因为现在我添加了一些导航按钮,OnNavigatedFrom 被调用但失败了,因为 _pageKey 为空,因为它不是由 OnNavigatedTo 设置的.
I know something is broken because now that I've added some navigation buttons, the OnNavigatedFrom is called but falls over because _pageKey is null since it wasn't set by OnNavigatedTo.
我实际上很困.这是 Microsoft 原生 Page 类的失败,但显然我是唯一一个遇到此问题且 100% 可发现的人.奇怪.
I actually am pretty stuck. This is a failing in Microsoft's native Page class, but clearly I'm the only person to have this issue and its 100% discoverable. Odd.
更新 1
我添加了一个新的 Grid App 项目,而且效果很好.通用内容作为标准内容全部存在,但它与将基本页面添加到空应用程序时编写的通用内容不同.
I added a new Grid App project and that works. The Common stuff is all there as standard but it does differ from the Common stuff that's written when you add a Basic Page to an empty app.
我将尝试从一个全新的空应用程序中复制此内容.
I will try and repro this from a fresh empty app.
更新 2
好吧,我放弃了.一个新的空白应用程序并添加一个新的空白页面就可以了.我会复制并粘贴我的页面,并假装它从未发生过.
Well, I give up. A new Blank App and adding a new Blank Page is fine. I'll just copy and paste my page over and pretend it never happened.
推荐答案
我遇到了同样的问题,这是由于在我添加的基本页面中存在 OnNavigateTo 的空覆盖.
I had the same problem and it was due to the presence of an empty override of OnNavigateTo in the basic pages I've added.
public sealed partial class MvvmView1
{
public MvvmView1()
{
this.InitializeComponent();
}
/// <summary>
/// Invoked when this page is about to be displayed in a Frame.
/// </summary>
/// <param name="e">Event data that describes how this page was reached. The Parameter
/// property is typically used to configure the page.</param>
protected override void OnNavigatedTo(NavigationEventArgs e)
{
}
}
这篇关于Page.OnNavigatedTo 不会在 Windows Store 应用程序中调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!