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

Is there a way to get the homepage object from any of my child controls? As a possible solution, I see a bubble between parents here and stops as soon as the parent is of type PhoneApplicationPage. This is fine for me, but what if I need to do this from other pages? That is, how to get the main page of the application from anywhere in the application?

+6
windows-phone-7
source share
2 answers

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

You can always get into the RootFrame, as in the application area. So for example ...

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

The page where your application starts is located in WMAppManifest.xml ...

 <Tasks> <DefaultTask Name ="_default" NavigationPage="MainPage.xaml"/> </Tasks> 
+9
source share

I wanted to encapsulate the behavior of the pivot element inside the view class. Apparently, SelectionChanged rotates through each rotation element during startup, so I had to do the following:

 var frame = App.Current.RootVisual as PhoneApplicationFrame; if (null == frame) //during app load { container = App.Current.RootVisual as MainPage; } else //during pivot event; { container = frame.Content as MainPage; } 

A container is defined as a closed container MainPage = null; Weird

0
source share

All Articles