Skip to main content
All docs
V26.1
  • TagBoxTagDisplayTemplateContext<TData>.RemoveTagAction Property

    Specifies the predefined action that removes the tag.

    Namespace: DevExpress.Blazor

    Assembly: DevExpress.Blazor.v26.1.dll

    Declaration

    public EventCallback RemoveTagAction { get; }

    Property Value

    Type Description
    EventCallback

    An event handler delegate.

    Remarks

    Use the RemoveTagAction property to assign the remove tag’s action to a custom UI element in the tag display template.

    The following code snippet customizes a tag appearance according to its type and text.

    <DxTagBox Data="@Data"
              TextFieldName="@nameof(City.CityName)"
              TData="City"
              TValue="City"
              AllowCustomTags="true"
              @bind-Tags="@Tags"
              ListRenderMode="ListRenderMode.Virtual"
              SizeMode="Params.SizeMode"
              CssClass="cw-480"
              InputId="tbTagTemplate">
        <TagDisplayTemplate Context="tagContext">
            <div class="@GetTagClass(tagContext.IsCustom ? tagContext.DisplayText : tagContext.DataItem.CityName)">
                @tagContext.DisplayText
                <div @onclick="@tagContext.RemoveTagAction" class="tagbox-tag-template-close-btn-icon" role="button" aria-label="Remove tag"></div>
            </div>
        </TagDisplayTemplate>
    </DxTagBox>
    @* ... *@
    
    @code {
        IEnumerable<City> Data { get; set; }
        IEnumerable<string> Tags { get; set; }
    
        protected override async Task OnInitializedAsync() {
            Data = await WorldcitiesDataService.GetCitiesAsync();
            Tags = new List<string>() { "New York", "Los Angeles", "Tokyo" };
        }
    @* ... *@
    
        string GetTagClass(string cityName) {
            var result = "tagbox-tag-template";
            switch(cityName) {
                case "New York":
                    result += " tagbox-tag-template-NY";
                    break;
                case "Los Angeles":
                    result += " tagbox-tag-template-LA";
                    break;
                default:
                    break;
            }
            return result;
        }
    }
    

    TagBox Template

    Run Demo: TagBox - Tag Display Template

    See Also