【问题标题】:Pass special characters as string between Windows Phone 8 pages在 Windows Phone 8 页面之间传递特殊字符作为字符串
【发布时间】:2013-04-01 05:53:39
【问题描述】:

我正在尝试将用户在文本框中输入的特殊字符作为字符串传递,例如 &#

然后将这个字符串传递到下一页

NavigationService.Navigate(new Uri(String.Format("/Pages/EditNote.xaml?note={0}", strText), UriKind.Relative));

EditNote.xaml 页面然后检查 note 参数并获取其值

protected override void OnNavigatedTo(NavigationEventArgs e)
{
        base.OnNavigatedTo(e);

        if (NavigationContext.QueryString.ContainsKey("note"))
        {
            noteText = NavigationContext.QueryString["note"];
        }
}

问题是当noteText为非字母数字字符时,例如&#等,它总是为空。

我错过了什么?

【问题讨论】:

    标签: c# windows-phone-8 special-characters


    【解决方案1】:

    由于特殊字符在url构造中具有预定义的含义,因此会与带有特殊字符的url+数据混淆。

    如果在您的上下文中没问题,您也可以使用 IsolatedStorageSettings。

    源页面:

    IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
    
    if (!settings.Contains("note"))
    {
         settings.Add("note", "$#$#$#%#%#????===&&&&&some note Text!#@#@@@  someText @$$@%@%@%@^@@&^*@&(*(**)*)_((_(_(_*(&*(^*&%&%*)");
    }
    
    settings.Save();
    
    NavigationService.Navigate(new Uri(@"/Pages/EditNote.xaml", UriKind.Relative));
    

    目标页面:

    string note = string.Empty;
    IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
    if (settings.Contains("note"))
    {
        note = settings["note"] as string;
    }
    

    在这里你可以传递所有特殊字符。

    【讨论】:

      【解决方案2】:

      尝试使用 UrlEncoding 对特殊字符进行编码。

      【讨论】:

        猜你喜欢
        • 2013-12-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-02-16
        • 2016-07-24
        • 1970-01-01
        • 2012-09-07
        • 1970-01-01
        相关资源
        最近更新 更多