Reputation: 81
I want to create user given number of TextBlock and TextBox in my windows phone silverlight app project.
At first, user will input an integer "num". Then I will create num number of TextBlock and TextBox.
I've tried generating an array to create TextBlocks and so far I've been unsuccessful. I've not tried to create TextBox yet. Here's what I've done so far:
public getPersonName(int num) //num is the number that user has input
{
InitializeComponent();
TextBlock[] txtFriend=new TextBlock[num]; //creating array txtFriend of num items
double left = 99;
for(int i=0;i<num;i++) //generating array
{
txtFriend[i]=new TextBlock();
txtFriend[i].Text = Convert.ToString(i);
txtFriend[i].Margin=new Thickness(left,10,0,0); //defining TextBlock margin
left++; //Increasing left margin so that each TextBlock is visible
}
}
Upvotes: 1
Views: 128
Reputation: 31024
You can change the stack panel control to whatever control you use:
public void TextBoxGenerator(int num)
{
TextBox txt;
for (int i = 0; i < num; i++)
{
txt = new TextBox();
txt.Text = (i+1).ToString();
stackpanel1.Children.Add(txt);
}
}
Upvotes: 1