![](/img/trans.png)
[英]How to add items dynamically to LongListSelector Windows Phone 8
[英]Add Items Dynamically to New Page - Windows Phone 8
我試圖通過詢問用戶textBoxes的數量來動態添加TextBox。 此代碼正在運行,但是將項目添加到當前位置。
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)而不是這里。
幫助將被挪用。
嘗試通過導航參數將其傳遞到第二頁
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));
然后在新頁面的onnavigation方法上做這個..
IDictionary<string, string> parameters = NavigationContext.QueryString;
string number= parameters["msg"];
然后從int num =0;
做你的代碼int num =0;
等等
我希望它可能有所幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.