Windows phone 7 如何从WindowsPhone7应用程序的任何部分获取主页?

Windows phone 7 如何从WindowsPhone7应用程序的任何部分获取主页?,windows-phone-7,Windows Phone 7,有没有办法从主页对象的任何子控件获取主页对象?作为一种可能的解决方案,我在这里看到,当父项为PhoneApplicationPage类型时,会在父项中冒泡并立即停止。这对我来说很好,但是如果我需要在其他页面上这样做呢? 例如,如何从应用程序中的任何地方获取应用程序的主页?在App.xaml中,有一个名为RootFrame的公共属性,它的类型为。它是as的容器 您始终可以访问根框架,因为它位于应用程序范围内。所以,举个例子 var frame = Application.Current.RootV

有没有办法从主页对象的任何子控件获取主页对象?作为一种可能的解决方案,我在这里看到,当父项为PhoneApplicationPage类型时,会在父项中冒泡并立即停止。这对我来说很好,但是如果我需要在其他页面上这样做呢?
例如,如何从应用程序中的任何地方获取应用程序的主页?

在App.xaml中,有一个名为RootFrame的公共属性,它的类型为。它是as的容器

您始终可以访问根框架,因为它位于应用程序范围内。所以,举个例子

var frame = Application.Current.RootVisual as PhoneApplicationFrame;
var startPage = frame.Content as PhoneApplicationPage;
应用程序启动的页面位于
WMAppManifest.xml

<Tasks>
  <DefaultTask  Name ="_default" NavigationPage="MainPage.xaml"/>
</Tasks>

我想在视图类中封装透视项的行为。显然,SelectionChanged在启动期间会在每个枢轴项目中循环,因此我必须执行以下操作:

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;
}
容器定义为私有主页容器=null; 奇怪