Silverlight导航问题

时间:2009-11-12 21:52:22

标签: silverlight navigation

我正在尝试导航到传递参数的页面,我必须从主页上工作,但是当我尝试在较低级别执行类似的操作时,我得到一个页面未找到错误(索引页面有效,但是DetailsIndex没有)

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.ContentFrame.Source = new Uri("/index?id=19", UriKind.Relative);

IndexPage.xaml.cs(收到错误 - &gt;未找到页面:“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));            
    }

2 个答案:

答案 0 :(得分:2)

您应该使用Uri导航,而不是使用映射的Uri。

this.NavigationService.Navigate(new Uri(string.Format("DetailsIndex/{0}", id), UriKind.Relative));  

此外,在映射中的Uris中,我认为它们通常以领先的/.

开头

答案 1 :(得分:0)

经过一些调查后,我发现以下解决方案对我有用

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

这样我也可以传递查询字符串