DxResource(String, Int32) Constructor
Initializes a new instance of the DxResource class with specified settings.
Namespace: DevExpress.Blazor
Assembly: DevExpress.Blazor.Resources.v24.2.dll
NuGet Package: DevExpress.Blazor.Resources
Declaration
public DxResource(
string resourcePath,
int position
)
Parameters
Name | Type | Description |
---|---|---|
resourcePath | String | The resource path. |
position | Int32 | The position in the Resource Manager’s script collection. |
Remarks
If you use a DevExpress Blazor project template, your application automatically registers all scripts DevExpress libraries require. To register these scripts in other Blazor applications, call the DxResourceManager.RegisterScripts method in the Components/App.razor file:
<head>
@*...*@
@DxResourceManager.RegisterScripts()
</head>
The method parameter allows you to specify client resources to be registered. The Resources field returns the resource collection. Register(DxResource) and Unregister(DxResource) methods allow you to add or remove scripts.
The following example registers a custom script.js script and removes the Quill resource. Quill is unnecessary if an application does not include the HTML Editor component:
@DxResourceManager.RegisterScripts((config) => {
config.Unregister(BlazorResources.QuillJS);
var maxScriptPosition = config.Resources.OrderBy(o => o.Position).Last().Position;
config.Register(new DxResource("script.js", maxScriptPosition + 1));
})
If you register a custom script, call the LoadDxResources(IJSRuntime) method before you execute the script’s API members for the first time. This method forces the Resource Manager to load client resources:
// ...
@code {
[Inject] IJSRuntime js;
protected override async Task OnAfterRenderAsync(bool firstRender) {
if(firstRender) {
await js.LoadDxResources();
await js.InvokeAsync("a-method-from-a-custom-script");
}
await base.OnAfterRenderAsync(firstRender);
}
}
Refer to the following topic for the list of DevExpress resources: DxResourceManager.