I am new to WPF. I am trying to create a page that is created at run time that is dependent upon a combobox selection. The combobox selection has 2,3,4,5 and the number selected will create a set of text boxes on the next page dynamically.
Should I use a content template or control template or data template with binding and triggers or is there another way to create dynamic textboxes that are dependent on user selection?
well, i think there is not THE one way to do something like this
you could use some
ItemsControlon the next page and provide it with (at least one)DataTemplatethat sets up aTextBoxor something else you like to have on the next page …here is an example that will add some controls to a
ListBoxwhenever you click on aButtonXAML:
Code behind:
as you can see I only have a Collection of objects, and I add bools and Strings …
the datatemplate gets selected based on the Type of the Object (you could use your own Types here instead of primitives)
so for creating controls on another page/window, you could setup a collection of View-Models, bind that to an ItemsControl, and have a DataTemplate for each Type instead of creating every control on your own with code behind …
but this is only one way to do that … not necessarily THE way