Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
229 views
in Technique[技术] by (71.8m points)

c# - How to navigate to another project inside same solution

Hey Hope somebody can help.

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:

How to navigate to view from another project

Which gives me the following

    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.

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?

Extra

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

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.

ODD

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 =?

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

OVerview of reference and included the full path to the elements enter image description here

enter image description here

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.

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:

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));

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...