Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

Get Started with Blazor Rich Text Editor

  • 3 minutes to read

This topic describes how to create a new project or configure an existing project to use a DevExpress Rich Text Editor component.

#Create a New Project (DevExpress Templates)

Follow this tutorial to create a Blazor application based on DevExpress project templates. To add the Rich Text Editor to the application, set the Add Rich Text Editor Resources option to true on the Settings tab.

Project Wizard - Settings

#Configure an Existing Project (Microsoft Templates)

Follow the steps below to incorporate the Rich Text Editor into a Blazor app created with a Microsoft template.

#1. Register Common DevExpress Resources

Install the DevExpress.Blazor NuGet package and register DevExpress resources used for all DevExpress Blazor components.

Read Tutorial: Create a Project

Read Tutorial: Register DevExpress Blazor Resources

#2. Register Rich Text Editor Resources

  1. Install the DevExpress.Blazor.RichEdit NuGet package.

    1. Select ToolsNuGet Package ManagerManage NuGet Packages for Solution.

    2. In the invoked dialog, open the Browse tab, select the DevExpress package source, and install the DevExpress.Blazor.RichEdit NuGet package.

    The DevExpress package is automatically added as a package source to your NuGet configuration files if you use the DevExpress .NET Product Installer.

    NuGet Package Manager

  2. Register the Rich Text Editor’s CSS file in the <head> section of the Components/App.razor file for Blazor Web applications.

    We recommend that you refresh cached resources on user machines to avoid rendering issues. For example, you can add a file version to a theme link as follows:

    cshtml
    <link href=@AppendVersion("_content/DevExpress.Blazor.Themes/blazing-berry.bs5.min.css") rel="stylesheet" />
    
    @code {
        private string AppendVersion(string path) => $"{path}?v={typeof(DevExpress.Blazor.ResourcesConfigurator).Assembly.GetName().Version}";
    }
    

    Note: this solution requires that you move a theme link to a Razor component in hybrid applications.

    You can find another solution that uses IFileVersionProvider in applications generated by our project templates. This solution does not work in Blazor hybrid applications.

    Such techniques ensure that web browsers on user machines use the current version of DevExpress CSS resources instead of the previously cached version. Refer to HTTP caching for more information about the browser cache.

    cshtml
    <head>
        @* ... *@
        <link href=@AppendVersion("_content/DevExpress.Blazor.RichEdit/dx-blazor-richedit.css") rel="stylesheet" />
    </head>
    
    @code {
        private string AppendVersion(string path) => $"{path}?v={typeof(DevExpress.Blazor.ResourcesConfigurator).Assembly.GetName().Version}";
    }
    
  3. Register the DevExpress.Blazor.Office and DevExpress.Blazor.RichEdit namespaces in the Components/Imports.razor file:

    @using DevExpress.Blazor.Office
    @using DevExpress.Blazor.RichEdit
    
  4. Optional. Set up the Rich Text Editor’s culture. See the following topic for details: Localization.

#Add a Rich Text Editor

Add the <DxRichEdit /> tag to the Pages/Index.razor page. Blazor Rich Text Editor does not support static render mode. You need to enable interactivity on a Razor page to allow Blazor Rich Text Editor to execute scripts and display data.

@rendermode InteractiveServer

<DxRichEdit />

Run the application to see the result:

Rich Text Editor