1

I have a Page class in a project A. I want to navigate to this page from my Universal windows project(say Project B) page. In UWP I am trying to achieve this using Frame.Navigate(typeof(Page_classA)), since NavigationService.Navigate(new Uri()) is obsolete in UWP.

But I get a Windows.UI.Xaml.Markup.XamlParseException in this case. Is there any other way in UWP or metro Apps for navigating to a page in different assembly?

Tulika
  • 625
  • 1
  • 8
  • 23

1 Answers1

2

We can use Frame.Navigate(TypeName) method to navigate to a page in different assembly.

For example, we can create a Class Library(Universal Windows) named "ProjectA" and in this project add a new Page named "PageA". Then in this project's Properties page, check the "Generate library layout" option in the Build configuration.
enter image description here

In WinRT environment, the resources are no longer embedded in the assembly but are placed next to the dll as content. So we need to generate library layout so that we can reference the dll in other project conveniently.

After this, we can build the project and we will get following layout in "Debug" folder: enter image description here
In ProjectA folder, it contains .xaml file and .xr.xml file: enter image description here

When we get the library output files, we can copy them to anywhere and in the Universal Windows Project(Project B), we just need to add reference to the "ProjectA.dll" file. Visual Studio will automatically pick these files up and put them in the appx package when it builds the app.

And in Project B, we can use following code to navigate to PageA:

Frame.Navigate(typeof(ProjectA.PageA))

In your case, you get a Windows.UI.Xaml.Markup.XamlParseException, this may be that the .pri file is missing when you add the reference. Here is a similar case. So please check your library layout and make sure these resources are are placed next to the dll you referenced.

Community
  • 1
  • 1
Jay Zuo
  • 15,653
  • 2
  • 25
  • 49
  • So you mean to say whenever we give a library project .dll to a user, its pri files and the .xbf files are mandatory to be given along with it? – Tulika Jan 25 '16 at 06:07
  • 1
    @user1917864: Yeah, if the library project contains XAML resources, we need these files are placed next to the .dll as in WinRT environment, the resources are no longer embedded in the assembly. If you want to publish your library to other user, you can refer to [this](http://stackoverflow.com/a/34611883/5506161) to package it as a NuGet package. – Jay Zuo Jan 25 '16 at 08:05