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

IBarButton Interface

A button on the Rich Text Editor‘s ribbon or toolbar.

Namespace: DevExpress.Blazor.Office

Assembly: DevExpress.Blazor.v24.2.dll

NuGet Package: DevExpress.Blazor

#Declaration

C#
public interface IBarButton :
    IBarItemWithImageBase,
    IBarItem,
    IBarItemBase

#Remarks

The following code snippet creates a custom Watermark button.

Razor
@inject NavigationManager NavigationManager

<DxRichEdit @ref=rich 
            CustomizeToolbar=OnCustomizeToolbar 
            BarMode=BarMode.Toolbar/>

@code {
    Selection selection;
    DxRichEdit rich;

    void OnCustomizeToolbar(IToolbar toolbar) {
        BarGroupCollection groups = toolbar.Groups;
        groups.Clear();
        AddFileCommonGroup(groups);
        // ...
    }

    void AddFileCommonGroup(BarGroupCollection groups) {
        IBarGroup fileCommonGroup = groups.Add(RichEditRibbonGroupNames.FileCommon);
        // ...

        // Adds a custom button
        IBarButton insertWatermarkButton = fileCommonGroup.Items.AddCustomButton("Watermark", InsertWatermarkAsync);
        insertWatermarkButton.GetEnabled = () => selection.ActiveSubDocument.Type == SubDocumentType.Main;
        insertWatermarkButton.IconUrl = "_content/BlazorDemo/images/Watermark.svg";
        insertWatermarkButton.Tooltip = "Insert Watermark.";
    }    

    async Task InsertWatermarkAsync() {
        rich.DocumentAPI.BeginUpdate();
        Section section = await rich.DocumentAPI.Sections.GetAsync(0);
        try {
            SubDocument header = await section.GetHeaderAsync(createIfNotExist: true);
            Image image = await header.Images.CreateAsync(0, DocumentImageSource.LoadFromUrl(NavigationManager.BaseUri + "_content/BlazorDemo/images/SampleWatermark.png", 5000, 5000));
            await image.ChangePropertiesAsync(ip => {
                ip.HorizontalAnchorElement = FloatingObjectHorizontalAnchorElement.Page;
                ip.VerticalAnchorElement = FloatingObjectVerticalAnchorElement.Page;
                ip.HorizontalAlignment = FloatingObjectHorizontalAlignment.Center;
                ip.VerticalAlignment = FloatingObjectVerticalAlignment.Center;
            });
        }
        finally {
            rich.DocumentAPI.EndUpdate();
        }
    }
}

Add a Custom Button

Run Demo: Toolbar Customization

See Also