DxTagBox<TData, TValue>.ItemDisplayTemplate Property
Specifies a template used to display the TagBox’s items in the drop-down list.
Namespace: DevExpress.Blazor
Assembly: DevExpress.Blazor.v24.2.dll
NuGet Package: DevExpress.Blazor
Declaration
[Parameter]
public RenderFragment<TagBoxItemDisplayTemplateContext<TData>> ItemDisplayTemplate { get; set; }
Property Value
Type | Description |
---|---|
RenderFragment<TagBoxItemDisplayTemplateContext<TData>> | The template content. |
Remarks
Place HTML markup in the <ItemDisplayTemplate>
tag to define custom content for TagBox items. Use the template’s context
parameter to access a data object and its fields (for instance, get the value of a data field).
The following code snippet uses the ItemDisplayTemplate
property to display TagBox items in a card-like view. Each item shows an employee’s first name, last name, photo, and phone number.
@inject NwindDataService NwindDataService
<DxTagBox Data="@Data"
@bind-Values="@Values">
<TagDisplayTemplate Context="tagContext">
<div class="tagbox-tag-template">
<img class="tagbox-tag-template-employee-photo" src="@StaticAssetUtils.GetImagePath(GetImageFileName(tagContext.DataItem))" alt="@tagContext.DataItem.FullName" />
<div>@tagContext.DataItem.FullName</div>
<DxButton Click="@tagContext.RemoveTagAction"
@onclick:stopPropagation
aria-label="Remove Tag"
CssClass="tagbox-tag-template-close-btn"
IconCssClass="tagbox-tag-template-close-btn-icon"
RenderStyle="ButtonRenderStyle.None" RenderStyleMode="ButtonRenderStyleMode.Text">
</DxButton>
</div>
</TagDisplayTemplate>
<ItemDisplayTemplate>
<div class="tagbox-item-template">
<img class="tagbox-item-template-employee-photo" src="@StaticAssetUtils.GetImagePath(GetImageFileName(context.DataItem))" alt="@context.DataItem.FullName" />
<div>
<span class="tagbox-item-template-employee-first-name">@context.DataItem.FullName</span>
<span class="tagbox-item-template-employee-home-phone">@context.DataItem.HomePhone</span>
</div>
</div>
</ItemDisplayTemplate>
</DxTagBox>
@code {
IEnumerable<Employee> Data { get; set; }
IEnumerable<Employee> Values { get; set; }
protected override async Task OnInitializedAsync() {
Data = await NwindDataService.GetEmployeesAsync();
Values = Data.Take(1);
}
string GetImageFileName(Employee employee) {
return $"employees/item-template{employee.EmployeeId}.jpg";
}
}
Implements
DevExpress.Blazor.ITagBox<TData, TValue>.ItemDisplayTemplate
See Also