So I've written some code that creates TextBlocks from a list of strings by calling a for loop:
List<string> menuPages = new List<string>() { "Home", "Media", "Settings" };
//method called from constructor:
private void createHeaders ()
{
for (int i=0; i<menuPages.Count; i++)
{
TextBlock iheader = new TextBlock();
iheader.Name = menuPages[i];
iheader.Text = menuPages[i];
if (i==pageIndex)
{ iheader.FontSize = 36; }
else
{ iheader.FontSize = 32; }
stacky.Children.Add(iheader); //Adding button to stack panel
}
}
Now I've been writing another method that would cycle through each TextBlock in a loop and change the text to whatever I intend. I'd gotten a foreach loop working for the stackPanel children: (TextBlock tBlock in stacky.Children) but I need to work with an indexed for loop. The code below is how I WANT to achieve this:
//Re-render headers
for (int i = 0; i < menuPages.Count; i++)
{
//TextBlock menuPages[i].text = "foo";
}
Now of course the syntax above doesn't work so my question is, how can I address the TextBlocks from the strings in a list?