Skip to main content
All docs
V25.1
  • DxResource Class

    Identifies a client resource in the Resource Manager.

    Namespace: DevExpress.Blazor

    Assembly: DevExpress.Blazor.Resources.v25.1.dll

    NuGet Package: DevExpress.Blazor.Resources

    Declaration

    public class DxResource

    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 default script folder is wwwroot.

    Note: Omit the method call if you created a hybrid project. Our Blazor components obtain scripts for interaction automatically.

    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.

    Inheritance

    Object
    DxResource
    See Also