如何导航到同一解决方案中的另一个项目 [英] How to navigate to another project inside same solution

查看:23
本文介绍了如何导航到同一解决方案中的另一个项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿希望有人能帮忙.

我在许多不同的项目上进行了小组开发,现在我们想将这些结合起来.因此,我将项目包括在内.在启动项目中,我包含了对其他项目的引用.然后我使用另一个 stackoverflow 线程中的代码:

I have in group developed on many different projects and we now want to combine these. I therefore include the projects. In the startup project I include the reference to the other projects. And then I use the code from another stackoverflow thread:

如何导航到另一个项目的视图

这给了我以下内容

    NavigationService.Navigate(new Uri("/MVVMTestApp;/component/View/MainPage.xaml", UriKind.Relative));

项目构建并运行.但是当我按下应该激活代码的按钮时,在执行该行之后/期间出现错误.

The project builds and runs. But when I press the button that should activate the code I get an error after/during the execution of the line.

中断错误位于 MainPage.g.cs 文件中,如下所示:

The break error is located in the MainPage.g.cs file which looks like:

namespace MVVMTestApp {


public partial class MainPage : Microsoft.Phone.Controls.PhoneApplicationPage {

    internal System.Windows.Controls.TextBlock MainPageTitle;

    internal System.Windows.Controls.TextBlock LEgE;

    private bool _contentLoaded;

    /// <summary>
    /// InitializeComponent
    /// </summary>
    [System.Diagnostics.DebuggerNonUserCodeAttribute()]
    public void InitializeComponent() {
        if (_contentLoaded) {
            return;
        }
        _contentLoaded = true;
        *******System.Windows.Application.LoadComponent(this, new System.Uri("/MVVMTestApp;component/View/MainPage.xaml", System.UriKind.Relative));**
        this.MainPageTitle = ((System.Windows.Controls.TextBlock)(this.FindName("MainPageTitle")));
        this.LEgE = ((System.Windows.Controls.TextBlock)(this.FindName("LEgE")));
    }
}
}

我插入星星的那一行就是它断的地方.我需要做什么才能让它发挥作用?

The line where I inserted the stars, is where it breaks. What do I need to do to make it work?

额外

正如评论中所说,我需要在组件前包含一个正斜杠/",这很奇怪,因为它没有在任何地方使用,否则就像上面的链接和这个链接

As told in the comments, I need to include a forwardslash "/" before component, which is odd since it is not used in any place, else like the link above and this link

http://www.geekchamp.com/tips/wp7-navigating-to-a-page-in-different-assembly

但是包括正斜杠,我得到一个错误,即我指向的地方不存在任何 xaml 文件.排除正斜杠,我得到一个 XamlParseException 发生....

But including the forwardslash I get an error that there does not exist any xaml file where I point. Excluding the forwardslash and I get a XamlParseException occured....

所以我仍然遇到导航到另一个项目中的视图的问题.

So I still have the problem of navigating to a view in another project.

奇数

我现在不必在组件之前使用前导正斜杠.只要我写MVVMTestAppAssembly.我查看了程序集文件,但找不到包含的内容 =?

I now do not have to have the leading forwardslash before component. As long as I write MVVMTestAppAssembly. I have looked in the assembly files and cannot find this included =?

我在查看 msdn 后尝试了一下http://msdn.microsoft.com/en-us/library/cc296240%28v=vs.95%29.aspx

I tried it out after looking at msdn http://msdn.microsoft.com/en-us/library/cc296240%28v=vs.95%29.aspx

但仍然没有运气,让导航正常工作

But still no luck, with getting the navigation to work

参考概述并包含元素的完整路径

一种解决方案正如一个答案中所述,一种解决方案是使用 Windows Phone 类库.但是当我使用 MVVM 结构时,我无法让 viewmodelLocator 工作.因此,这对我来说不是解决方案.

One Solution As stated in one answer one solution is to use the windows phone class library. But when I use MVVM structure, I cannot get the viewmodelLocator to work. Therefore, this is not a solution for me.

但是如果您使用 MVVM,我需要另一种解决方案.希望有人对此有想法.另一种解决方案如下面的回答所述,您可以使用以下内容解决方案 1:

But if you use MVVM, I need another solution. Hopefully somebody has an idea for this. Another solution As stated below in an answer you can use the following Solution 1:

您使用相同类型的项目Windows Phone App".在该解决方案中,您需要有一个 Windows Phone 应用项目,其他项目应为 Windows Phone 类库类型.

You use the same type of projects "Windows Phone App". In the solution you need to have one Windows Phone App project and other projects should be of type Windows Phone Class Library.

然后,您可以使用以下代码行导航以在同一解决方案中的另一个项目中查看:

Then you can navigate to view in another project inside same solution with this line of code:

    NavigationService.Navigate(new Uri("/MVVMTestApp;/component/View/MainPage.xaml", UriKind.Relative));

在项目之间导航.但是,您在生成的 xaml 文件 FILENAME.g.cs 中出现错误,其中插入了行 loadcomponent.据我所知,由于数据上下文将视图连接到视图模型,因此发生错误.我一直没能解决它.

To navigate between projects. However you get an error in the generated xaml file FILENAME.g.cs where it inserts the line loadcomponent. The error occurs because of the view being connected by datacontext to a viewmodel, as far as I can understand. And I have not been able to solve it.

希望有人对此有解决方案吗?

Hopfully somebody has a solution for this?

推荐答案

把组件"前的/"去掉,像这样:

Just remove "/" before "component", like this:

NavigationService.Navigate(new Uri("/MVVMTestApp;component/View/MainPage.xaml", UriKind.Relative));

NavigationService.Navigate(new Uri("/MVVMTestApp;component/View/MainPage.xaml", UriKind.Relative));

这篇关于如何导航到同一解决方案中的另一个项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆