title: Getting values from dynamically generated controls
body: <p>I am generating wpf form dynamically. All the controls are generated dynamically as follows</p>
  
  <p>A sample code snippet</p>
  
  <pre><code>String tbname = name;
  TextBlock txtBlock1 = new TextBlock();
  txtBlock1.Text = tbname;
  
  Grid.SetRow(txtBlock1, count);
  Grid.SetColumn(txtBlock1, icount);
  SampleGrid.Children.Add(txtBlock1);
  TextBox txtBox = new TextBox();
  txtBox.Text = ptiAttribute.description;
  txtBox.Name = tbname.Replace(" ", "");
  DynamicGrid.RegisterName(txtBox.Name, txtBox);
  Grid.SetRow(txtBox, count);
  Grid.SetColumn(txtBox, icount+1);
  SampleGrid.Children.Add(txtBox);
  </code></pre>
  
  <p>Attaching a button click event as follows</p>
  
  <pre><code>var Button = CreateButton("Save", 15, 3);
  Button.Click += new RoutedEventHandler(button_Click);
  SampleGrid.Children.Add(Button);
  </code></pre>
  
  <p>I would like to get all the control values (For example: The above text box has value Book), I have to get it after button click. I am not only having text box. I have combo box, date picker too. I don't know which name is registered (RegisterName). Every thing dynamic.</p>
  
  <pre><code>private static void button_Click(object sender, RoutedEventArgs e)
  {
     # How  to get dynamic values here (text bx value, date picker value, combo box value)
  }
  </code></pre>
  
  <p>Simply, how to get values from dynamically generated controls. I have gone through a lot of <strong>Visual tree</strong> links but I don't know how it works on button click.</p>
  
  <p>Any simple code snippet will help me to move ahead. Thanks</p>