带有查询字符串的 URI 映射器似乎不起作用 [英] URI Mapper with query string doesn't seem to work

查看:51
本文介绍了带有查询字符串的 URI 映射器似乎不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试设置一个 URI 映射器,以便最后我可以将查询字符串传递给我正在加载的 xaml 页面.

I'm attempting to set up a URI mapper so that in the end, I can pass a query string to the xaml page I am loading.

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

Here's what I have defined in the 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/Foo"之类的链接,Foo"将作为查询字符串传递到需求"页面,然后我们就可以用它来施展魔法了.

My Intention is that if you click on a link such as '/RequirementOverview/Foo' "Foo" is passed as a query string to the Requirement page, and then we can do our magic with it.

但是,当调用 Fame.Navigate("RequirementOverview/Foo", UriKind.Relative) 时,我总是以这样的方式结束页面:hostpage.aspx#/RequirementOverview/Foo 并且没有查询传递到页面.相反,它似乎工作(导航),但我的 navigationContext queryString 返回 null.

However when calling Fame.Navigate("RequirementOverview/Foo", UriKind.Relative) I always end up at the page like thus: hostpage.aspx#/RequirementOverview/Foo and no query is passed to the page. Rather, it seems to work (the navigation), but my navigationContext queryString comes back null.

我的做法不正确吗?提前致谢.

Is my approach for this incorrect? Thanks in advance.

推荐答案

您在浏览器中获得的 URL (hostpage.aspx#/RequirementOverview/Foo) 是您应该期望的,因为您使用的是映射的 URI.

The URL that you get in the bowser (hostpage.aspx#/RequirementOverview/Foo) is what you should expect since you're using mapped URIs.

>

要获取 QueryString 参数,您只需覆盖页面的 OnNavigatedTo,访问 QueryString(这是一个Dictionary) 属性 NavigationContextPage 类的成员,如下所示:

To get the QueryString parameters, all you have to do is override the OnNavigatedTo of your page, access the QueryString (which is a Dictionary<string,string>) property of the NavigationContext which is a member of the Page class, like this:

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

希望这有帮助:)

这篇关于带有查询字符串的 URI 映射器似乎不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆