动态添加项目到新页面 - Windows Phone 8

时间:2013-06-21 07:09:13

标签: c# windows-phone-7 windows-phone-8 windows-phone

我正在尝试动态添加TextBoxes,方法是询问用户textBoxes的数量。 此代码正在运行,但是将项目添加到当前位置。

NavigationService.Navigate(new Uri("/Page1.xaml?shouldDownload=true",     UriKind.Relative)); //Naviagte on new page
int num;
int.TryParse(textBox1.Text, out num); //Converting textbox to int
for (int i = 1; i <= num; i++)
{
    TextBox newtext = new TextBox();
    newtext.Text = i.ToString();
    newtext.Margin = new Thickness(300, (i * 80), 0, 0);
    newtext.Width = 124;
    newtext.Height = 68;
    //button.VerticalAlignment = 234;
    //Add contentpanel to your page if there's not one already.
    ContentPanel.Children.Add(newtext);
    newtext.Visibility = System.Windows.Visibility.Visible;
}

但我想将这些项目添加到新页面(即:Page1)而不是这里。

帮助将被挪用。

2 个答案:

答案 0 :(得分:2)

尝试通过导航参数

将其传递到第二页
string num = textBox1.Text;
NavigationService.Navigate(new Uri("/Page1.xaml?shouldDownload=true&num="+num,     UriKind.Relative)); //Naviagte on new page

在第二页中,您将在OnNavigatedTo方法中解析结果

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    base.OnNavigatedTo(e);
    string numValue;
    if (NavigationContext.QueryString.TryGetValue("num", out numValue))
    {
        int num = Convert.ToInt32(numValue);
        // add 'em here
    }
}

答案 1 :(得分:0)

你可以试试这个......

NavigationService.Navigate(new Uri("/Page1.xaml?shouldDownload=true&msg=" + extBox1.Text,     UriKind.Relative));

然后在新页面的onnavigation方法上做这个..

 IDictionary<string, string> parameters = NavigationContext.QueryString;
 string number= parameters["msg"];

然后从中做你的代码 int num =0;等等

我希望它可以帮助

相关问题