将项目动态添加到新页面-Windows Phone 8
本文关键字:-Windows Phone 新页面 项目 动态 添加 | 更新日期: 2023-09-27 18:19:32
我试图通过询问用户文本框的数量来动态添加文本框。此代码正在工作,但正在将项添加到当前位置。
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;
}
但我想将这些项目添加到新页面(即:第1页),而不是此处。
帮助将被挪用。
尝试通过导航参数将其传递到您的第二个页面
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
}
}
你可以试试这个。。。
NavigationService.Navigate(new Uri("/Page1.xaml?shouldDownload=true&msg=" + extBox1.Text, UriKind.Relative));
然后在新页面的导航方法上这样做。。
IDictionary<string, string> parameters = NavigationContext.QueryString;
string number= parameters["msg"];
然后从执行代码int num =0;
等
我希望它能帮助