Adding a component dynamically
Last updated
Last updated
WebMap provides a built-in mechanism to new controls during the runtime execution without having to directly modify the front-end layer of the application, however, this mechanism has some requirements that need to be met.
The control must not be declared in the front-end application.
Its name must be unique.
The Add container logic must be invoked outside the InitializeComponent method.
The following properties are strictly necessary:
Name
Position (Top, Left)
Size (Width, Height)
The control must exist in both the front-end components and the back-end models.
To know the more about the currently supported front-end controls please visit this section.
To be able to add a new control dynamically the following steps must be made.
Step 1. Adjust the current container to allocate the new control.
This process could be made in both the back-end application by directly modifying its source code or in the front-end by applying style changes. For this scenario the modification will be directly applied in the back-end application.
In this case the new logic will be added into the application constructor.
The result of the code modification will be reflected into the application the next time the back-end gets compiled.
Step 2. Once the control container has been modified accordingly, it is time to add a new instance for the desired control.
For the following example a new method (CreateNewButton) will be added, this method contains the necessary logic to create a new button instance, including its required properties needed to render in the front-end.
Note: the name property needs to be unique.
Step 3. Lastly the only remaining step is to add the newly created control into the list of the current controls included in its container
Step 4. Compile the back-end code and the new control should now be available to use.