I am working on windows phone 8 app.
I am dynamically creating multiple Textview and Grid inside For loop.
for (int j = 0; j < 300; j++)
{
Image image = new Image();
image.Source = new BitmapImage(new Uri("/Images/sample256.png", UriKind.RelativeOrAbsolute));
image.Tag = i.ToString();
Grid questionGrid = new Grid();
questionGrid.HorizontalAlignment = HorizontalAlignment.Center;
questionGrid.VerticalAlignment = VerticalAlignment.Center;
TextBlock question = new TextBlock();
question.TextWrapping = TextWrapping.Wrap;
question.TextAlignment = TextAlignment.Center;
question.Text = " this is the question and its id is Question" + i;
question.FontSize = 30;
question.Foreground = new SolidColorBrush(Colors.Black);
question.HorizontalAlignment = HorizontalAlignment.Center;
questionGrid.Children.Add(question);
Grid answerGrid = new Grid();
answerGrid.HorizontalAlignment = HorizontalAlignment.Center;
answerGrid.VerticalAlignment = VerticalAlignment.Center;
TextBlock answer = new TextBlock();
answer.TextWrapping = TextWrapping.Wrap;
answer.TextAlignment = TextAlignment.Center;
answer.Text = "this is answer and its id is Answer" + i;
answer.FontSize = 30;
answer.Foreground = new SolidColorBrush(Colors.Black);
answer.HorizontalAlignment = HorizontalAlignment.Center;
answerGrid.Children.Add(answer);
LayoutRoot.Children.Add(image);
LayoutRoot.Children.Add(questionGrid);
LayoutRoot.Children.Add(answerGrid);
}
As you can see that i have around 300 times its entering, so because of that the load is heavy and there is a lot of delay when page responds to user interaction.
How to reduce the load? so that i can resue the dyamically created views.