I create a form in run-time from some parameters in a list of fields.
List<Fields> lstFields = new List<Fields>()
{
new Fields(){ FieldType = Fields.fieldTypes.INPUT, Info = "Some Info", Label = "first", Mandatory= true},
new Fields(){ FieldType = Fields.fieldTypes.CHK, Info ="Some Info", Label="Second",
Items = new List<String>(){"item1","item2","item3","item4"} },
new Fields(){ FieldType = Fields.fieldTypes.INPUT, Label = "Name", Mandatory= true},
new Fields(){ FieldType = Fields.fieldTypes.INPUT, Label = "Surname", Mandatory= true},
new Fields(){ FieldType = Fields.fieldTypes.COMBO, Label = "City", Mandatory = false,
Items = new List<String>(){"item1","item2","item3","item4"}}
}
I create my fields in a foreach statement:
foreach (Fields fd in lstFields)
{
[...]
switch (fd.FieldType)
{
case Fields.fieldTypes.INPUT:
TextBox currentTB = new TextBox(); //It violates MVVM pattern :(
content.Add(currentTB);
[...]
break;
[...]
default:
break;
}
}
}
I need a form validation strategy. All the strategies that I know are based on the binding. The problem is that I can not bind the property because I create the controls dinamically. I would like to solve the problem following the MVVM design pattern.