Reputation: 2104
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 (i.e: Page1) not here.
Help will be appropriated.
Upvotes: 0
Views: 1237
Reputation: 12465
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
}
}
Upvotes: 2
Reputation: 1313
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
Upvotes: 0