简体   繁体   中英

Add Items Dynamically to New Page - Windows Phone 8

I'm trying to Add TextBoxes dynamically, by asking user the number of textBoxes. This code is working and but adding items to present place.

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

But I want to add these Items to new page (ie: Page1) not here.

Help will be appropriated.

Try passing this to your second page via the navigation params

string num = textBox1.Text;
NavigationService.Navigate(new Uri("/Page1.xaml?shouldDownload=true&num="+num,     UriKind.Relative)); //Naviagte on new page

In your second page your parse the result within the OnNavigatedTo method

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

you can try this...

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

then on the onnavigation method of the new page do this ..

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

then do your code from int num =0; and so on

I hope that it might help

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM