Badge

in namespace DotVVM.Bootstrap5.Controls

Renders a Bootstrap badge widget.

Usage & Scenarios

Renders a Bootstrap badge component.

https://getbootstrap.com/docs/5.2/components/badge/

Sample 1: Basic Badge

Place the contents of the Badge inside the control, or use the Text property.

The Type property specifies the color category of the badge.

You can use the VisualStyle to specify, whether the badge should have a normal shape, or whether it should be rendered as a pill.

<bs:Badge Text="100"/>

<bs:Badge>
  <h1>9000+</h1>
</bs:Badge>

<bs:Badge Type="Primary" VisualStyle="Pill" />

Sample 2: Badge in a Button

If you need to use the Badge inside the button, don't forget to set the ButtonTagName to Button.

Otherwise, the button would be rendered as <input type="button"> which supports only a text values.

<bs:Button Click="{command: Increment()}" ButtonTagName="button">
  Number of clicks: <bs:Badge Text="{value: Clicks}"/>
</bs:Button>
public class ViewModel : DotvvmViewModelBase
{
    public int Clicks { get; set; } = 0;

    public void Increment()
    {
        Clicks++;
    }
}

Sample 3: Badge as Link or Button

The Badge control can work as a button.

  • The Click event can be used to invoke a command in the viewmodel.
<bs:Badge Text="{value: Clicks + ' clicks'}" 
            Click="{command: Increment()}" />
public class ViewModel : DotvvmViewModelBase
{
    public int Clicks { get; set; } = 0;

    public void Increment()
    {
        Clicks++;
    }
}

Properties

Name Type Description Notes Default Value
property icon Content List<DotvvmControl> Gets or sets the content inside the badge.
attribute
inner element
static value
bindable
default
null
property icon Text String Gets or sets the text inside the control.
attribute
inner element
static value
bindable
default
null
property icon Type BadgeColor Gets or sets the Bootstrap color of the badge.
attribute
inner element
static value
bindable
default
Primary
property icon Visible Boolean Gets or sets whether the control is visible. When set to false, `style="display: none"` will be added to this control.
attribute
inner element
static value
bindable
default
True
property icon VisualStyle BadgeVisualStyle Gets or sets the visual style of the badge.
attribute
inner element
static value
bindable
default
Default

Events

Name Type Description
event icon Click ICommandBinding Gets or sets the command that will be triggered when the badge is clicked.

HTML produced by the control