2011-07-26 19 views
1

我试图建立一个URI映射器,以便最终,我可以传递一个查询字符串到我加载的xaml页面。与查询字符串的URI映射器似乎并不工作

这是我在XAML中定义的内容。

<navigation:Frame.UriMapper> 
    <uriMapper:UriMapper> 
     <uriMapper:UriMapping Uri="RequirementOverview/{id}" MappedUri="/View/Pages/RequirementOverview.xaml?id={id}" /> 
     <uriMapper:UriMapping Uri="/{pageName}" MappedUri="/View/Pages/{pageName}.xaml"/> 
    </uriMapper:UriMapper> 
</navigation:Frame.UriMapper> 

我的意思是,如果你点击作为查询字符串的要求页面传递的链接,如“/ RequirementOverview /美孚”“富”,然后我们可以做我们的魔力吧。

但是,当调用Fame.Navigate(“RequirementOverview/Foo”,UriKind.Relative)时,我总是以如下方式在页面结束:hostpage.aspx#/ RequirementOverview/Foo并且没有查询被传递给页面。相反,它似乎工作(导航),但我的navigationContext查询字符串返回null。

我的方法是不正确的?提前致谢。

+0

我想知道,如果你需要删除最后一个/在 “Frame.Navigate(” RequirementOverview /富 “UriKind.Relative)”。其他一切看起来都适合我。 – Aligned

+0

啊,最后一个斜线是偶然的,我会编辑帖子。 – Brandorf

回答

2

您在bowser中获得的URL(hostpage.aspx#/ RequirementOverview/Foo)是您使用映射URI后所期望的。

要获得QueryString参数,所有你需要做的就是重写你的页面的OnNavigatedTo,访问QueryString(这是一个Dictionary<string,string>)的NavigationContext的属性,它是Page类的成员,像这样:

protected override void OnNavigatedTo(NavigationEventArgs e) 
{ 
    try 
    { 
     var id = int.Parse(NavigationContext.QueryString["id"]; 
    } 
    catch{} 
} 

希望这有助于:)