Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何将多个字符串值从一个页面传递到另一个页面?_C#_Navigation_Query String_Windows Phone 8.1 - Fatal编程技术网

C# 如何将多个字符串值从一个页面传递到另一个页面?

C# 如何将多个字符串值从一个页面传递到另一个页面?,c#,navigation,query-string,windows-phone-8.1,C#,Navigation,Query String,Windows Phone 8.1,我了解了如何使用查询字符串将一个值作为字符串从文本框从一个页面传递到另一个页面 但我不知道如何传递多个字符串值,例如,我有一个wrkTbx、rstTbx和roundTbx 如何将这三个值传递到另一个页面 这是我当前的实现: 训练页面: private void appBarAddBtn_Click(object sender, EventArgs e) { NavigationService.Navigate(new Uri("/MainP

我了解了如何使用查询字符串将一个值作为字符串从文本框从一个页面传递到另一个页面

但我不知道如何传递多个字符串值,例如,我有一个wrkTbx、rstTbx和roundTbx

如何将这三个值传递到另一个页面

这是我当前的实现:

训练页面:

        private void appBarAddBtn_Click(object sender, EventArgs e)
        {
            NavigationService.Navigate(new Uri("/MainPage.xaml?key=" + wrkTbx.Text, UriKind.Relative));
        }
private void appBarAddBtn_Click(object sender, EventArgs e)
{
    string url = "/MainPage.xaml" +
        "?wrkTbx=" + System.Net.WebUtility.UrlEncode(wrkTbx.Text) +
        "&rstTbx=" + System.Net.WebUtility.UrlEncode(rstTbx.Text) +
        "&roundTbx=" + System.Net.WebUtility.UrlEncode(roundTbx.Text);

    NavigationService.Navigate(new Uri(url, UriKind.Relative));
}
主页:

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            if (NavigationContext.QueryString.ContainsKey("key"))
            {
                string val = NavigationContext.QueryString["key"];
                MessageBox.Show("value is:  " + val);
            }

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

    if (NavigationContext.QueryString.ContainsKey("wrkTbx"))
    {
        string wrkTbx = NavigationContext.QueryString["wrkTbx"];
        MessageBox.Show("wrkTbx value is: " + wrkTbx);
    }

    if (NavigationContext.QueryString.ContainsKey("rstTbx"))
    {
        string rstTbx = NavigationContext.QueryString["rstTbx"];
        MessageBox.Show("rstTbx value is: " + rstTbx);
    }

    if (NavigationContext.QueryString.ContainsKey("roundTbx"))
    {
        string roundTbx = NavigationContext.QueryString["roundTbx"];
        MessageBox.Show("roundTbx value is: " + roundTbx);
    }

}

您可以使用符号(
&
)分隔多个查询字符串参数。但您还需要确保对这些值进行正确编码,因为它们可能包含特殊字符(例如,符号)

这是您的代码的修改版本,它传递您提到的所有值

训练页面:

        private void appBarAddBtn_Click(object sender, EventArgs e)
        {
            NavigationService.Navigate(new Uri("/MainPage.xaml?key=" + wrkTbx.Text, UriKind.Relative));
        }
private void appBarAddBtn_Click(object sender, EventArgs e)
{
    string url = "/MainPage.xaml" +
        "?wrkTbx=" + System.Net.WebUtility.UrlEncode(wrkTbx.Text) +
        "&rstTbx=" + System.Net.WebUtility.UrlEncode(rstTbx.Text) +
        "&roundTbx=" + System.Net.WebUtility.UrlEncode(roundTbx.Text);

    NavigationService.Navigate(new Uri(url, UriKind.Relative));
}
主页:

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            if (NavigationContext.QueryString.ContainsKey("key"))
            {
                string val = NavigationContext.QueryString["key"];
                MessageBox.Show("value is:  " + val);
            }

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

    if (NavigationContext.QueryString.ContainsKey("wrkTbx"))
    {
        string wrkTbx = NavigationContext.QueryString["wrkTbx"];
        MessageBox.Show("wrkTbx value is: " + wrkTbx);
    }

    if (NavigationContext.QueryString.ContainsKey("rstTbx"))
    {
        string rstTbx = NavigationContext.QueryString["rstTbx"];
        MessageBox.Show("rstTbx value is: " + rstTbx);
    }

    if (NavigationContext.QueryString.ContainsKey("roundTbx"))
    {
        string roundTbx = NavigationContext.QueryString["roundTbx"];
        MessageBox.Show("roundTbx value is: " + roundTbx);
    }

}
对于wp8

//send data
NavigationService.Navigate(new Uri("/MainPage.xaml?key=" + wrkTbx.Text + "&key2=" + wrkTbx2.Text, UriKind.Relative));

//retrive the information 
string key,stringKey2;
int key2;
if (NavigationContext.QueryString.TryGetValue("key", out key)){
  // use key value
}
if (NavigationContext.QueryString.TryGetValue("key2", out stringKey2)){
    key2 = Int32.Parse(stringKey2); // use key2 value
}
对于winndows phone8.1

public class model
{
   public string key{ get; set; }
   public int key2{ get; set; }
}

//send data
Frame.Navigate(typeof(MainPage), new PassedData { key= "my name", key2= 10 });

// get data
protected override void OnNavigatedTo(NavigationEventArgs e){
    model= e.Parameter as model;
}

名称“服务器”不存在。这在windows phone 8.1中可用吗?我必须添加一些描述吗?我在发布代码后意识到它使用的是ASP.NET版本的UrlEncode。检查修改后的“训练页面”代码,以及我在上面添加的“注意事项”,看看是否有效。只是尝试了编辑后的代码,System.web无法识别。添加了一个using.System。但是没有.Web的引用您是否向
System.Web.dll
程序集添加了项目引用?(假设它甚至在Windows Phone应用程序仅限于的.NET framework的“便携”版本中可用…)我认为它不可用,尝试在解决方案资源管理器中添加引用,但没有System.Web