You can try to create a single StackPanel for all of the TextBoxes. For example this way,
StackPanel panel = new StackPanel();
panel.Name = "myPanel";
for (int i = 0; i < 13; i++ ) {
TextBox textBox = new TextBox();
panel.Children.Add(textBox);
}
You can also use the XAML for doing this type of job, if you like so.
You can then use the Children property of the MainWindow's grid, make sure that you've given that grid a name, for example
<Grid name="mainGrid">
The program logic would be something like,
foreach (StackPanel childPanel in mainGrid.Children.OfType<stackpanel>()) {
if(childPanel.Name == "myPanel") {
int index = 0;
int index2 = 0;
foreach (TextBox box in childPanel.Children.OfType<textbox>()) {
index++;
foreach (TextBox aBox in childPanel.Children.OfType<textbox>()) {
index2++;
if(index != index2) {
if(box.Text == aBox.Text) {
MessageBox.Show("Found a duplicate.");
break;
}
}
}
}
}
}
A lot of headache, isn't it?