简体   繁体   English

WP8如何导航到另一个项目页面

[英]Wp8 How do I navigate to another project page

My problem is in navigating to another project file "ChatMeApp/MainPage.xaml" from my original project. 我的问题是从我的原始项目导航到另一个项目文件“ ChatMeApp / MainPage.xaml”。 My code is 我的代码是

private void GoToChat(object sender, EventArgs e)
{
    this.NavigationService.Navigate(new Uri("/ChatMeApp;component MainPage.xaml", UriKind.RelativeOrAbsolute));
} 

When I run this I get an exception in app.xaml.cs and it breaks here 当我运行它时,我在app.xaml.cs中得到一个异常,它在这里中断

// Code to execute if a navigation fails
private void RootFrame_NavigationFailed(object sender, NavigationFailedEventArgs e)
{
    if (System.Diagnostics.Debugger.IsAttached)
    {
        // A navigation has failed; break into the debugger
        System.Diagnostics.Debugger.Break();
    }
}

I'm fairly new to WP8 development (coming from ac# background). 我是WP8开发的新手(来自ac#背景)。 All the advise I've seen makes me think this should work, can any one see a problem with it or suggest what else the problem might be. 我所看到的所有建议都使我认为这应该可行,任何人都可以解决此问题或提出其他可能的问题。

I am assuming that you are trying to navigate to /MainPage.xaml within your current project . 我假设您正在尝试导航到当前项目中的 /MainPage.xaml。 In that case you can achieve your goal with the following code. 在这种情况下,您可以使用以下代码实现目标。

private void GoToChat(object sender, EventArgs e)
{
    NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
} 

If you are trying to navigate to a page in another app, this isn't possible. 如果您尝试导航到另一个应用程序中的页面,则不可能。

您在Uri中的“组件”之后有一个额外的空间。

new Uri("/ChatMeApp;component/MainPage.xaml", UriKind.Relative));

Actullay you are trying to Navigate to another Assembly, you can also achive this by the source code pasted below. 您尝试导航到另一个程序集的Actullay,也可以通过下面粘贴的源代码来实现。

Both case are pasted below 两种情况都粘贴在下面

private void Button_Click_1(object sender, RoutedEventArgs e)
{
    //Navigate to a page in the current assembly
    NavigationService.Navigate(new Uri("/Page1.xaml", UriKind.Relative));
}

 private void Button_Click(object sender, RoutedEventArgs e)
{
    //Navigate to a page in an external referenced assembly
    NavigationService.Navigate(new Uri("/AnotherProject;component/MainPage.xaml",   UriKind.Relative));
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM