How to get inputs from dynamically created WPF controls?

I am creating a questionnaire application in WPF. The GUI displaying the questionnaire to the user is built dynamically at runtime through code depending on an XML questionnaire definition. The questions in the questionnaire can be multiple choice questions, yes/no quesitons and free text questions. I create text blocks representing question bodies and then depending on whether the question is multiple choice (I create a set of radio buttons to represent the choices) or yes no (two radio buttons - one for yes and other for no) or free text (text box for collecting user input). My problem is when the user clicks a submit button, I need to collect the answers from the controls and store them back to my object. How do I do this?
Kumara_SanjayaAsked:
Who is Participating?
 
CuteBugCommented:
I would suggest you make a usercontrol.
The user control will handle multiple choice questions. Depending on how many options are there, add that many radio buttons and set them in one group.
Have a property (say Result) within the user control. each time a radio button is clicked, set the appropriate value of the Result property.

Use this user control to create the Yes No question control.

Using this control, you can save the Result property for the multiple choice or Yes No questions.
0
 
Kumara_SanjayaAuthor Commented:
I have to do everything in code....I cannot use design time support....is it possible to create a user control without writing any XAML...as I have to write everything as C# code which builds the control dynamically at runtime?

Can you please post a small example...even if very small...just as a guidance for me to start with?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.