I have a WPF application that allows users to create questions of all different types which depending on the type will use a textbox,combobox,checkboxes, or radio buttons to allow the user to answer the question after they build some sort of questionnaire. My question is what is the best way to keep track of the answers across all the different controls after the controls are created and the questionnaire is created on the fly. Right now, i’m looping through all the containers and getting the values based on the controlType. Which this works fine but I’m wondering if databinding or something else would somehow provide me a better solution.
My hiccup with databinding is that i don’t have the structure of the expected answers or questions until after everything is created so it can be different everytime. I know this is a little vague but i’d really appreciate any help anyone can provide. thanks.
Id create classes that represents each type of question (ie one that would require a testbox answer, one for combobox, etc). Also create a datatemplateselector to select which template you want and create a resource in the xaml for this selector.
Classes:
Instantiation Code:
XAML: