I am developing a WPF 4.0 application where I need to make a grid that contains a column with either textbox or a dropdown depending on the row. Example:
| Name | Value | Help |
| PROP1A | [textbox] | Description of prop1a |
| Prop2A | [dropdown v] | Description of prop2a |
| Prop3A | [textbox] [x checkbox] | Description of prop2a |
| Prop4A | [dropdown v] | Description of prop2a |
| etc...
The idea is that the user has a table of values that they need to input, and we display the name and description for each value alongside. Some of the values are numbers that need to be input with a textbox, while others are a textbox plus a checkbox, and still others are a dropdown.
My initial thought was to implements this as basically a collection of what I'll call RowDescriptor
s that would specify the name, input type and help info (which is just text), and then use binding to bind the collection to the DataGrid. Basically, these would act as ViewModels, and setting the value in the DataGrid would flow up through the ViewModel to the actual Model (just like the in the typical case for an MVVM app).
As I looked through the documentation I have available, though, I couldn't find anywhere that discussed a way of changing the type of the column dynamically like this. I am now leaning toward using a Grid instead, and manually laying out the inputs (still using Binding, but binding each element individually). This will be a lot more manual effort on my part though, so I wanted to find out if there was a relatively-straightforward way of implementing my first idea. It seems like I should be able to do something with DataGridTemplateColumn, but I'm relatively new to WPF and I'm not sure exactly how I'd go about doing this.