Getting Started with Blazor Toolbar Component

10 Nov 20214 minutes to read

This section briefly explains about how to include a Toolbar in the Blazor server-side application. Refer Getting Started with Syncfusion Blazor for Server-Side in Visual Studio page for the introduction and configuring the common specifications.

To get started quickly with Blazor Toolbar, check on this video:

Importing Syncfusion Blazor component in the application

Use any one of the below standards to install the Syncfusion Blazor library in the application.

Using Syncfusion Blazor individual NuGet Packages [New standard]

Starting with Volume 4, 2020 (v18.4.0.30) release, Syncfusion provides individual NuGet packages for the Syncfusion Blazor components. This new standard is highly recommended for the Blazor production applications. Refer to this section to know the benefits of the individual NuGet packages.

  1. Install Syncfusion.Blazor.Navigations NuGet package to the application using the NuGet Package Manager.

  2. Add the client-side style resources through CDN or from NuGet package in the <head> element of the ~/Pages/_Host.cshtml page.

     <head>
         ....
         ....
         <link href="_content/Syncfusion.Blazor.Themes/bootstrap4.css" rel="stylesheet" />
     </head>

    WARNING

    Syncfusion.Blazor package should not be installed along with the individual NuGet packages. Hence, the above Syncfusion.Blazor.Themes static web assets (styles) have to be added in the application.

Using Syncfusion.Blazor NuGet Package [Old standard]

WARNING

If the above new standard (individual NuGet packages) is preferred, then skip this section. Using both old and new standards in the same application will throw ambiguous compilation errors.

  1. Install Syncfusion.Blazor NuGet package to the newly created application by using the NuGet Package Manager.

  2. The client-side style resources can be added through CDN or from NuGet package in the <head> element of the ~/Pages/_Host.cshtml page.

     <head>
         ....
         ....
         <link href="_content/Syncfusion.Blazor/styles/bootstrap4.css" rel="stylesheet" />
          @*<link href="https://cdn.syncfusion.com/blazor/19.3.43/styles/bootstrap4.css" rel="stylesheet" />*@
     </head>

    For Internet Explorer 11 kindly refer the polyfills. Refer the documentation for more information.

     <head>
         ...
             <link href="https://cdn.syncfusion.com/blazor/19.3.43/styles/bootstrap4.css" rel="stylesheet" />
             <script src="https://github.com/Daddoon/Blazor.Polyfill/releases/download/3.0.1/blazor.polyfill.min.js"></script>
         ...
     </head>

Adding component package to the application

Open ~/_Imports.razor file and import the Syncfusion.Blazor.Navigations package.

@using Syncfusion.Blazor.Navigations

Add SyncfusionBlazor service in Startup file

Open the Startup.cs file and add services required by Syncfusion components using services.AddSyncfusionBlazor() method. Add this method in the ConfigureServices function as follows.

using Syncfusion.Blazor;

namespace BlazorApplication
{
    public class Startup
    {
        ....
        ....
        public void ConfigureServices(IServiceCollection services)
        {
            ....
            ....
            services.AddSyncfusionBlazor();
        }
    }
}

Adding Toolbar component to the application

Now, add the Syncfusion Blazor Toolbar component in any web page (razor) in the Pages folder. For example, the Toolbar component is added in the ~/Pages/Index.razor page.

@using Syncfusion.Blazor.Navigations

<SfToolbar>
    <ToolbarItems>
        <ToolbarItem Text="Cut"></ToolbarItem>
        <ToolbarItem Text="Copy"></ToolbarItem>
        <ToolbarItem Text="Paste"></ToolbarItem>
        //To separate the Toolbar items
        <ToolbarItem></ToolbarItem>
        <ToolbarItem Text="Bold"></ToolbarItem>
        <ToolbarItem Text="Underline"></ToolbarItem>
        <ToolbarItem Text="Italic"></ToolbarItem>
        <ToolbarItem Text="Color-Picker"></ToolbarItem>
    </ToolbarItems>
</SfToolbar>

Run the application

After successful compilation of the application, simply press F5 to run the application.

Blazor Toolbar

See Also

  1. Getting Started with Syncfusion Blazor for client-side in .NET Core CLI
  2. Getting Started with Syncfusion Blazor for client-side in Visual Studio 2019
  3. Getting Started with Syncfusion Blazor for server-side in .NET Core CLI