views:

371

answers:

1

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));            
    }
+1  A: 

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 /.

Bryant
thanks... It does work with the "/", I had some very weird behaviour where it was navigating to the page, and then the error was coming up when I used the navigationcontext... which threw me.I am also debating using a singleton pattern instead of passing parameters this way... it seems a bit clunky
grayson mitchell