Windows phone 7 如何在WIndows Phone应用程序中获得access NavigationService,而无需浏览PhoneApplicationPage?
如何在Windows Phone应用程序中获得access NavigationService,而无需浏览PhoneApplicationPage?我的目标是在启动时将其传递给应用程序的主视图模型,这是一种在WPF和Silverlight中对我非常有效的技术。您可以从应用程序的Windows phone 7 如何在WIndows Phone应用程序中获得access NavigationService,而无需浏览PhoneApplicationPage?,windows-phone-7,Windows Phone 7,如何在Windows Phone应用程序中获得access NavigationService,而无需浏览PhoneApplicationPage?我的目标是在启动时将其传递给应用程序的主视图模型,这是一种在WPF和Silverlight中对我非常有效的技术。您可以从应用程序的PhoneApplicationFrame中获得它。由于每个Windows Phone应用程序都有一个框架,因此可以从应用程序中的任何位置访问它 ((PhoneApplicationFrame)Application.Cu
PhoneApplicationFrame
中获得它。由于每个Windows Phone应用程序都有一个框架,因此可以从应用程序中的任何位置访问它
((PhoneApplicationFrame)Application.Current.RootVisual).Navigate(...);
另一个地方是从应用程序的默认实现中的RootFrame字段获取:
#region Phone application initialization
// Avoid double-initialization
private bool phoneApplicationInitialized = false;
// Do not add any additional code to this method
private void InitializePhoneApplication()
{
if (phoneApplicationInitialized)
return;
// Create the frame but don't set it as RootVisual yet; this allows the splash
// screen to remain active until the application is ready to render.
RootFrame = new PhoneApplicationFrame();
RootFrame.Navigated += CompleteInitializePhoneApplication;
// Handle navigation failures
RootFrame.NavigationFailed += RootFrame_NavigationFailed;
// Ensure we don't initialize again
phoneApplicationInitialized = true;
}
// Do not add any additional code to this method
private void CompleteInitializePhoneApplication(object sender, NavigationEventArgs e)
{
// Set the root visual to allow the application to render
if (RootVisual != RootFrame)
RootVisual = RootFrame;
// Remove this handler since it is no longer needed
RootFrame.Navigated -= CompleteInitializePhoneApplication;
}
#endregion
@道格-谢谢!很高兴能帮上忙:)谢谢你,伙计。也节省了我的时间。@Nexus-不客气。很高兴看到答案仍然有用:D