Sometimes a default generated panel is just not enough. You need to set specific properties, or want to use a special control. But you don't want to loose the easy binding features of the BindManager. You can still use standard binding, but you have to know how the BindManager works. Key is naming the controls correctly.
The BindManager uses a specific binder class for every type of control. There is a TextBoxBinder for a TextBox and a DropDownListBinder for a DropDownList, etc. When these binders are registered to the BindManager (ofcourse using DI
) they indicate which type of control they can bind. This is done by prefixes like 'txt' and 'ddl'.
When binding a DomainObject all the instance properties of the entity are listed and for every property a set of combinations they the prefix keys are generated. The control to which you are binding is then search for all these combinations. The format used is:
<key><type of DomainObject><name of property>
So if an entity
has a property
which should be represented in a TextBox, the control should have the name
In the default generated panel the control is generated as:
public partial class PanelUser : SmartPanel
protected override void OnInit(EventArgs e)
Add(ValidatedTextBoxItem.Create("Name", "UserName", 50, Editable, true));
As name is passed "UserName". The SmartPanel will generate the appropriate prefix for it, in this case "txt".
So, how to add your own control? There are two ways:
- Create a PanelItem for it and just use it directly in your existing panel. The advantage is it will be integrated in the layout of the other controls and maintains the consistency of your code.
- Create your own control and add it manually to the form. In that case you have to make sure you name it correctly so it's possible to use the BindManager.
Here is an overview of default web binders and which prefixes they use.
For windows there are the following binders:
If you cannot use one of above binders for your special control, you can create your own binder by just implementing the
interface. Register it by adding it to the application config file.