I have developed a prototype framework (MVVM) where control on the form is bound to a model property using a naming convention and its UI behavior is controlled using custom attributes.
As of now the control name is divided into two parts - 3 part prefix and then the Name of the property in model to bind to.
For eg
txtFirstNametextbox is bound toFirstNamein model. During construction/load, all controls are looped through -BaseEdit baseEdit = (BaseEdit) control; baseEdit.DataBindings.Add("EditValue", viewModelBindingSource, baseEdit.Name.Remove(0, 3), true, DataSourceUpdateMode.OnPropertyChanged);There are some other attributes such as [ReadOnly], [Unbound] which are used to control the UI behavior.
baseEdit.Properties.ReadOnly = Util.GetReadOnlyAttributeValue( control.Name.Remove(0, 3), viewModel.GetType());I am thinking of doing the looping the other way around, ie the Model properties, using a
Boundattribute.Bound[ControlName, PropertyName]Bound["txtFirstName", "EditValue"] FirstNameAll the dropdown type controls, combobox, dropdown, checkeddropdown etc are autofilled by using a 'Key' from their tag property.
if (control.GetType() == typeof(LookUpEdit) && !string.IsNullOrEmpty(Convert.ToString(control.Tag))) //Exact match { LookUpEdit lookUpEdit = (LookUpEdit)control; DataBinding.InitializeLookUpEdit(lookUpEdit, lookUpEdit.Tag.ToString()); }I took the biggest data-entry form with around 45 controls and tested the framework.
Is the above approach suitable for a big project? Any suggestions for improving the framework?