2

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

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

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 在它是非字母数字字符(例如 等)时将始终为&#

我错过了什么?

4

2 回答 2

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

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

于 2013-12-18T14:09:46.147 回答
0

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

于 2013-04-01T19:54:27.227 回答