How to navigate to another project inside same solution

此生再无相见时 提交于 2019-11-28 12:26:21

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

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

First you have to give reference to the Parent Project then

you can solve that issue via this line

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

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

Solution 2:

Go to Configuration Manager in Debug.

Uncheck Deploy check-box from MVVMTestApp.

I think the issue lies in your setup. From your description you name your project MVVMTestApp. I assume this is the start up project. However, your reference is from TestUserControls to MVVMTestApp. This is backwards. I know based on what you are trying to do it seems right, but it is not (unless your project naming is messed up.)

I suggest you have two projects:

  • MVVMTestApp (Windows Phone 8.1 Universal App which is start up project)
  • MVVMTestApp.Lib (Portable Class that supports Windows Phone 8.1)

Add a reference from MVVMTestApp to MVVMTestApp.Lib.

MVVMTestApp will have MainPage.xaml & SecondPage.xaml.

I suggest that your Lib only has Shared User Controls and not Pages to be navigated to. You can put the user control on SecondPage.

If you do want to have the SecondPage in your Shared Lib, it will be tougher to handle but still possible. However you won't be able to use the code everyone else has suggested. It doesn't make sense to have the Shared code call MVVMTestApp because then it is not really shareable. What if you had another app that you were sharing with called MVVMTestApp2. Your could would not work if you had MVVMTestApp hard coded even it you could make it work with MVVMTestApp and therefore you would not have any benefit of putting SecondPage in a separate project.

To have a shareable page that calls back to the app I'm thinking you have two options. You could use Inversion of Control and define INavigationService in your Lib. Then in your MVVMTestApp implement INavigateService and register your implementation with your favorite Ioc container. Then in your Lib you can call a method on your INavigationService. In your MVVMTestApp implementation you can use the code provided in the other posts to navigate to main page.

Another option would be to expose an event in your Lib. You listen to the event from MVVMTestApp and in the handler you navigate to MainPage like in the other posts. In your Lib you would Raise the event when you want to navigate to MainPage.

Good luck & Have fun,

Tom

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!