How to get current page in my WP7 app

后端 未结 2 1990
陌清茗
陌清茗 2021-02-05 04:14

Is there a way to get the active instance of the current page in my Windows Phone 7 app? I have been reading documentation and trying to figure it out to no avail.

In my

2条回答
  •  心在旅途
    2021-02-05 04:42

    You can get the current page from the root frame. The default App class that is generated in the project has a RootFrame property that is already of type PhoneApplicationFrame. The value of the Content property is the current page and can be cast to PhoneApplicationPage.

    var currentPage = ((App)Application.Current).RootFrame.Content as PhoneApplicationPage;

    The RootVisual property on the Application class references the same frame, but is a UIElement, so you could use the following instead:

    var currentPage = ((PhoneApplicationFrame)Application.Current.RootVisual).Content;

提交回复
热议问题