Windows Phone 7 - 在页面之间传递值 [英] Windows Phone 7 - passing values between pages

查看:27
本文介绍了Windows Phone 7 - 在页面之间传递值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下方法在页面之间发送值:

I am trying to send the values between the pages using :

NavigationService.Navigate(new Uri("/ABC.xaml?name=" + Company + "&city=" + City , UriKind.Relative));

这里 Company 和 City 值被传递到下一页,不知何故ABC & Ltd"之类的公司名称没有正确传递,它只是将ABC"传递到下一页.基本上是&"之后的部分被删除了.

Here the Company and City values are passed to the next page, somehow the Company names like "ABC & Ltd" is not passing properly,it just passes the "ABC" to next page. Basically the portion after "&" is dropped.

这里有格式化的选项吗???或者我应该为此写一个逻辑??

Is there an option here to format this ??? Or should i write a logic for this ??

需要帮助!

谢谢

推荐答案

如果您的任何查询字符串包含在 Uri 中被视为无效的字符,您正在执行的操作将会失败,正如您所发现的.您需要使用 Uri.EscapeDataString 首先转义任何非法字符.将您发布的代码更改为以下内容:

If any of your query strings contain characters that are considered invalid in a Uri what you're doing will fail, as you've discovered. You need to use Uri.EscapeDataString to escape any illegal characters first. Change the code you've posted to the following:

NavigationService.Navigate( new Uri( String.Format( "/ABC.xaml?name={0}&city={1}",
          Uri.EscapeDataString( Company ), Uri.EscapeDataString( City ) ), 
          UriKind.Relative ) );

当您使用NavigationContext.QueryString 读取转义字符串时,它们会自动取消转义,因此无需显式调用Uri.UnescapeDataString.

The escaped strings are automatically unescaped when you read them using NavigationContext.QueryString, so there's no need to call Uri.UnescapeDataString explicitly.

这篇关于Windows Phone 7 - 在页面之间传递值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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