title: c# wpf getting input from textbox in dynamically generated DataTemplate objects
body: <p>I'm a newcomer to C# WPF programming, and I'm having difficulty (spent a whole day on this) figuring out how to create a system where:</p>
  
  <p>1) A collection of UI elements (in a groupbox) is generated with a click of a button.</p>
  
  <p>2) The groupbox has a textbox (for int inputs) and a combobox (selection among strings). I need to populate combobox with the elements of a list. 
  I need to take input from the textbox and selection from combobox and place it in a List of my structs Rules{ String topic; int number}.</p>
  
  <p>This needs to be done for as many of the groupboxes the user generates.</p>
  
  <p>The main question I have is, how do I access these comboboxes to populate them? How Do i get input from them?</p>
  
  <p><strong>xaml</strong></p>
  
  <pre><code>&lt;Window x:Class="ExamMaker.MainWindow"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
          xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
          xmlns:local="clr-namespace:ExamMaker"
          mc:Ignorable="d"
          Title="Exam Preparation" Height="350" Width="525"
          Closing="Window_Closing"&gt;
      &lt;Window.Resources&gt;
          &lt;DataTemplate x:Key="ruleTemplate"&gt;
              &lt;GroupBox x:Name="Rulebox" Header="Rule " HorizontalAlignment="Left" Margin="10,0,0,0" VerticalAlignment="Top" Height="56" Width="468"&gt;
                  &lt;Grid HorizontalAlignment = "Left" Height="36" Margin="0,0,-2,0" VerticalAlignment="Top" Width="458"&gt;
                      &lt;Label x:Name="TopicRuleLabel" Content="Topic:" HorizontalAlignment="Left" Margin="5,4,0,0" VerticalAlignment="Top" Height="28"/&gt;
                      &lt;TextBox x:Name="NumberRuleTextBox" HorizontalAlignment="Left" Height="22" Margin="240,9,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="30" /&gt;
                      &lt;ComboBox x:Name="RuleComboBox" HorizontalAlignment="Left" Margin="50,9,0,0" VerticalAlignment="Top" Width="120"/&gt;
                      &lt;Label x:Name="NumberRuleLabel" Content="Number:" HorizontalAlignment="Left" Margin="179,4,0,0" VerticalAlignment="Top" Height="28"/&gt;
                  &lt;/Grid&gt;
              &lt;/GroupBox&gt;
          &lt;/DataTemplate&gt;
      &lt;/Window.Resources&gt;
      &lt;Grid&gt;
          &lt;TabControl x:Name="tabControl" HorizontalAlignment="Left" Height="319" VerticalAlignment="Top" Width="517"&gt;
              &lt;TabItem Header="Exam Preparation"&gt;
                  &lt;Grid Background="#FFE5E5E5" Margin="0,0,0,0"&gt;
                      &lt;ListView x:Name="listView" ItemsSource="{Binding Path=examQS}"&gt;
                          &lt;ContentControl ContentTemplate="{StaticResource ruleTemplate}"&gt;
  
                          &lt;/ContentControl&gt;
                      &lt;/ListView&gt;
                  &lt;/Grid&gt;
              &lt;/TabItem&gt;
              &lt;TabItem Header="Question Form" Margin="-2,0,0,0" HorizontalAlignment="Left" Width="95"&gt;
  
              &lt;/TabItem&gt;
              &lt;TabItem Header="Setup" HorizontalAlignment="Left" Height="20" VerticalAlignment="Top" Width="54"&gt;
  
              &lt;/TabItem&gt;
          &lt;/TabControl&gt;
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>As for the c#, well I only have one Observable collection in there and some methods for adding and removing items from it.</p>