Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Navigate to a XAML page in a different assembly in Windows Phone 7

I have a XAML page in a separate Windows Phone class library. The library is included in my VS solution and referenced from my app project. Let's say the page is called TestPage.xaml and it's in the root folder of my library called SharedPages.

I'd like to navigate to this page in my app using the NavigationService. I found this post which suggests using this URI format:

/{assemblyName};component/{pathToResource}

So I'm trying something like this:

NavigationService.Navigate(new Uri("/SharedPages;component/TestPage.xaml"));

When I run this I get the following exception:

Navigation is only supported to relative URIs that are fragments, or begin with '/', or which contain ';component/'.

What am I doing wrong?

Thanks.

like image 312
phantom Avatar asked Feb 13 '11 18:02

phantom


2 Answers

Looks like the URI needs to be created as a relative URI. This works:

NavigationService.Navigate(new Uri("/SharedPages;component/TestPage.xaml", UriKind.Relative));
like image 145
phantom Avatar answered Nov 20 '22 15:11

phantom


Hey I don't think it's your case, but it's good to review the generated assembly name.

Option 1) Incorrect Assembly name

The following format:

/{assemblyName};component/{pathToResource}

The assembly name can be checked it in the tab properties of the project. I remember a guy who has renamed the project but not the assembly and that was a reason because of the navigation was failing.

Option 2)

Dot separator in your assembly name.

I don't know the real reason of this, but I took me some time to found it. The name of the assembly must not have any dot as separator. I guess the Uri parse will incorrectly the Uri. For example I had an assembly called: "Com.Hmb.Prax" and I got the following exception:

Navigation is only supported to relative URIs that are fragments, or begin with '/', or which contain ';component/'.
Parameter name: uri

Once I rename my dll to "ComHmbPrax" it worked well. Herber

like image 4
hmadrigal Avatar answered Nov 20 '22 13:11

hmadrigal