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

DxContextMenuItem.IconUrl Property

Specifies a menu item icon’s URL.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v24.2.dll

NuGet Package: DevExpress.Blazor

#Declaration

C#
[DefaultValue(null)]
[Parameter]
public string IconUrl { get; set; }

#Property Value

Type Default Description
String null

A menu item icon’s URL.

#Remarks

Use the IconUrl property to specify the path to a menu item’s icon. The specified image is wrapped with the <img> tag when rendered. The resulting image is limited to 16px*16px.

You can use the IconUrl property to implement a dynamically visible check sign in the item.

Razor
<DxContextMenu ItemClick="@OnItemClick" >
    <Items>
        <DxContextMenuItem Text="Sort By" IconUrl="/images/sort.svg">
            <Items>
                <DxContextMenuItem Text="Name" IconUrl="@GetChecked("Name")" />
                <DxContextMenuItem Text="Size" IconUrl="@GetChecked("Size")" />
                <DxContextMenuItem Text="Type" IconUrl="@GetChecked("Type")" />
            </Items>
        </DxContextMenuItem>
        <DxContextMenuItem Text="Copy" IconUrl="/images/copy.svg" BeginGroup="true" />
        <DxContextMenuItem Text="Cut" IconUrl="/images/cut.svg" />
        <DxContextMenuItem Text="Remove" IconUrl="/images/clear.svg" />
        <DxContextMenuItem Text="Select All" BeginGroup="true" />
    </Items>
</DxContextMenu>

@code {
    string SortBy { get; set; }

    void OnItemClick(ContextMenuItemClickEventArgs args) {
        if (args.ItemInfo.Text == "Name" || args.ItemInfo.Text == "Size" || args.ItemInfo.Text == "Type")
            SortBy = args.ItemInfo.Text;
    }
    string GetChecked(string ItemText) {
        return (ItemText == SortBy) ? "/images/check.svg" : null;
    }
}

ContextMenu Items

Run Demo: Context Menu

See Also