Page.OnNavigatedTo doesn't get called in Windows Store app

萝らか妹 提交于 2019-12-06 04:26:05

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)
        {
        }
    }

In order for OnNavigatedTo to get called, your Frame must call its Navigate method.

Frame localFrame = this.MyFrame; //this assumes MyFrame is Frame that exists in xaml and has a name 

localFrame.Navigate(new myPage());

If you are using content injection

localFrame.Content  = new myPage();

The OnNavigatedTo event of myPage will not fire, because the page is loaded only, not navigated to.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!