A BlazorControl (or Blazor Component) is a reusable UI element that can contain HTML, CSS and C# logic. It is similar to web components in front end frameworks like React or Angular.
Blazor Controls are defined as ".razor" files and can be used throughout your HTML5 displays. See a solution example using Blazor at Solution Examples > Displays > BlazorControl Example.
On this page:
This component runs only on HTML5 displays, targeting web browsers.
Go to Displays / Draw.
On the Components Panel, select Viewer, then BlazorCtrl(Web).
Click or drag-and-drop it on the Drawing area to use it.
Select the file you want to use and click Open
Blazor Control Settings | |
---|---|
Field | Description |
Control Name | Defines a name for the control so it can be accessed in the CodeBehind script. See Display CodeBehind. |
Assembly | The name of the DLL that will be used. E.g.: BlazorControlExample.dll |
Type | The full name of the control that will be used. E.g.: BlazorControlExample.ProgressBar |
Dependencies | If the control does not contains css/javascript embedded and requires external files, add them all here by line. |
A Blazor Control usually requires input parameters and/or returns data from it. To link tags to them, we must bind the tags directly in the CodeBehind, and the right place to do it is inside the EventCallback that happens once the controls are fully loaded:
public async Task BlazorControlLoaded(TBlazorControl control) { } |
To do so, we must use the command BindEvent , that will create a link in between the Tag and the Parameter inside the control. There are two different cases and it requires some knowledge on the control itself, they are:
It is important to know when to use one or another, to make the right choice of how to bind them correctly. Below is a full example of the two bindings and their respective explanation.
public async Task BlazorControlLoaded(TBlazorControl control) { //The BindEvent can be used to bind bidirectional Tags to Blazor properties. It requires an EventCallback on the Blazor control to receive the value back into the Tag. // Parameter 1 - CurrentProdution - The name of the parameter inside the control // Parameter 2 - The name of the tag to link with the control // Parameter 3 - The name of the EventCallback that will raise the changes control.BindEvent("CurrentProduction", @Tag.CurrentProduction.GetName(), "CurrentProductionRestarted"); //Using "null" in the third property of the BindEvent function will set the Tag into the property in a one-way, so the tag will only send values to the control, it will never receive values back. control.BindEvent("TargetProduction", @Tag.TargetProduction.GetName(), null); control.BindEvent("BarColor", @Tag.BarColor.GetName(), null); } |
If you want to set a value directly, without bind any tag into it, you can use:
public async Task BlazorControlLoaded(TBlazorControl control) { //This event will be triggered for each Blazor Control in the display. //Using the TBlazorControl to access the desired Blazor control ProgressBar BlazorControlExample.ProgressBar myProgressBarComponent = control.BlazorComponent as BlazorControlExample.ProgressBar; //Once inside the control, you can access any parameter / property / method that has visibility privileges myProgressBarComponent.CurrentProduction = 150; } |
Once a command to close the display is triggered, the system will automatically Unbind all the tags that were Binded before. If at any moment you need to Unbind them manually, you can use the following code:
object eventBind; TBlazorControl blazorControl; public async Task BlazorControlLoaded(TBlazorControl control) { //Saves the control in memory for future reference blazorControl = control; //Bind the tag to the control and receives an object as return to be used later for a manual unbind eventBind = control.BindEvent("TargetProduction", @Tag.TargetProduction.GetName(), null); } public async Task ManualUnbind() { //Manually Unbind the event blazorControl.UnbindEvent(eventBind); } |
If at some point you have multiple controls on the same display, you can use the Uid property to decide what actions you will take based on the control you have:
public async Task BlazorControlLoaded(TBlazorControl control) { if(control.Uid == "ProgressBar") { //do this } else if(control.Uid == "LinearGauge") { //do that } } |
To install a Blazor Control, some steps must be followed, in order to achieve the right results. Below is a step by step on how to do it.
{ "builder.Services.1": "Mudblazor.Core.dll;MudBlazor.Services.ServiceCollectionExtensions;AddMudServices", "Initializer.1": "<assembly>;<type>;<method>", "Licensing.1": "<assembly>;<type>;<method>;<argument>", "LoadAssembly.1": "<assembly>", "css.1": "MudBlazorCSS.css", "js.1": "MudBlazorJS.js" } |
Where:
Initializer.json Settings | |
---|---|
Field | Description |
builder.Services.1 | A three parameters configuration:
|
Initializer.1 | The method from the "builder." to be called. E.g.: builder.Build(); |
Licensing.1 | The full path to the registration of the license. E.g.: Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("key"); |
LoadAssembly.1 | The full path to any external dependencies that are required to the control to work properly. |
css.1 | The .css file full path (starting at the root folder "BlazorControls"). |
js.1 | The .js file full path (starting at the root folder "BlazorControls"). |
In this section: