I am generating wpf form dynamically. All the controls are generated dynamically as follows
A sample code snippet
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);
Attaching a button click event as follows
var Button = CreateButton("Save", 15, 3);
Button.Click += new RoutedEventHandler(button_Click);
SampleGrid.Children.Add(Button);
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.
private static void button_Click(object sender, RoutedEventArgs e)
{
# How to get dynamic values here (text bx value, date picker value, combo box value)
}
Simply, how to get values from dynamically generated controls. I have gone through a lot of Visual tree links but I don't know how it works on button click.
Any simple code snippet will help me to move ahead. Thanks