Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get main page from any part of Windows Phone 7 application?

Is there any way of getting main page object from any of its child controls? As a possible solution I see here bubbling through parents and stopping as soon as a parent is of PhoneApplicationPage type. It is fine for me, but what if I need to do that from other pages? I.e. How to get main page of an application from everywhere within the application?

like image 962
Bashir Magomedov Avatar asked Oct 16 '10 23:10

Bashir Magomedov


1 Answers

In your App.xaml, there is a public property called RootFrame it is of type PhoneApplicationFrame class. It is the container for PhoneApplicationPages as discussed in this article.

You can always get to the RootFrame since it's at application scope. So, for example ...

var frame = Application.Current.RootVisual as PhoneApplicationFrame;
var startPage = frame.Content as PhoneApplicationPage;

The page that your app starts on is in WMAppManifest.xml ...

<Tasks>
  <DefaultTask  Name ="_default" NavigationPage="MainPage.xaml"/>
</Tasks>
like image 69
JP Alioto Avatar answered Sep 22 '22 01:09

JP Alioto