Reputation: 11
I am trying to navigate to pages passing parameters, which I have got to work from the mainpage, but when I try and do a similar thing at a lower level I get a page not found error (the index page works, but the DetailsIndex does not)
MainPage.xaml
<navigation:Frame.UriMapper>
<uriMapper:UriMapper x:Name="myUri">
<uriMapper:UriMapping Uri="" MappedUri="/Views/Home.xaml"/>
<uriMapper:UriMapping Uri="DetailsIndex/{id}" MappedUri="/Views/DetailsIndex.xaml?id={id}"/>
<uriMapper:UriMapping Uri="Index/{id}" MappedUri="/Views/Index.xaml?id={id}"/>
<uriMapper:UriMapping Uri="/{pageName}" MappedUri="/Views/{pageName}.xaml"/>
</uriMapper:UriMapper>
MainPage.xaml.cs (this works)
this.ContentFrame.Source = new Uri("/index?id=19", UriKind.Relative);
IndexPage.xaml.cs (this gets a error -> Page not found: "DetailsIndex?id=66")
private void Button_Click(object sender, RoutedEventArgs e)
{
Button btn = sender as Button;
string id = btn.Tag.ToString();
this.NavigationService.Navigate(new Uri(string.Format("DetailsIndex?id={0}", id), UriKind.Relative));
}
Upvotes: 1
Views: 1239
Reputation: 1
After doing some investigation I found the below solution which worked for me
Xaml :
<uriMapper:UriMapper>
<uriMapper:UriMapping Uri="" MappedUri="/Views/Home.xaml"/>
<uriMapper:UriMapping Uri="/{pageName}" MappedUri="/Views/{pageName}.xaml"/>
</uriMapper:UriMapper>
Codebehind:
private void HyperlinkButton_Click(object sender, RoutedEventArgs e)
{
HyperlinkButton hyp = sender as HyperlinkButton;
string customer_id = hyp.Tag.ToString();
this.NavigationService.Navigate(new Uri("/CustomerDetails?CustomerId=" + customer_id, UriKind.Relative));
}
This way I am able to pass the query string also
Upvotes: 0
Reputation: 8670
You should be navigating using the Uri, not the mapped Uri.
this.NavigationService.Navigate(new Uri(string.Format("DetailsIndex/{0}", id), UriKind.Relative));
Also, in the Uris in the mappings, I believe they usually start with a leading /.
Upvotes: 2