CheckBox

in namespace DotVVM.Controls.Tailwind.Controls

Renders a custom checkbox with a hidden native input and custom visual box.

Usage & Scenarios

The CheckBox control renders a Tailwind-styled checkbox. It supports both a single boolean value through Checked and multi-select scenarios with CheckedItems and CheckedValue.

Sample 1: Boolean Binding

Use the Checked property for a single boolean value. The control also supports Text, custom inner content, Enabled, and the Changed command.

<div class="space-y-3">
    <t:CheckBox Text="Receive product updates"
                Checked="{value: ReceiveUpdates}"
                Changed="{command: IncrementChanges()}" />

    <t:CheckBox Checked="{value: AcceptTerms}">
        <span>I accept the <strong>terms and conditions</strong>.</span>
    </t:CheckBox>

    <t:CheckBox Text="Locked option"
                Checked="{value: LockedOption}"
                Enabled="false" />
</div>

<p>Receive updates: <strong>{{value: ReceiveUpdates}}</strong></p>
<p>Terms accepted: <strong>{{value: AcceptTerms}}</strong></p>
<p><code>Changed</code> command count: <strong>{{value: ChangeCount}}</strong></p>
using DotVVM.Framework.ViewModel;

namespace DotvvmWeb.Views.Docs.Controls.tailwind.CheckBox.sample1
{
    public class ViewModel : DotvvmViewModelBase
    {
        public bool ReceiveUpdates { get; set; }

        public bool AcceptTerms { get; set; }

        public bool LockedOption { get; set; } = true;

        public int ChangeCount { get; set; }

        public void IncrementChanges()
        {
            ChangeCount++;
        }
    }
}

Sample 2: CheckedItems Collection

Use CheckedItems together with CheckedValue when multiple checkboxes should add and remove values in a collection.

<div class="space-y-2">
    <t:CheckBox Text="Apple" CheckedItems="{value: SelectedFruits}" CheckedValue="apple" />
    <t:CheckBox Text="Banana" CheckedItems="{value: SelectedFruits}" CheckedValue="banana" />
    <t:CheckBox Text="Cherry" CheckedItems="{value: SelectedFruits}" CheckedValue="cherry" />
</div>

<p>Selected fruits:
    <strong>{{value: SelectedFruits.Count == 0 ? "(none)" : string.Join(", ", SelectedFruits)}}</strong>
</p>
using DotVVM.Framework.ViewModel;
using System.Collections.Generic;

namespace DotvvmWeb.Views.Docs.Controls.tailwind.CheckBox.sample2
{
    public class ViewModel : DotvvmViewModelBase
    {
        public List<string> SelectedFruits { get; set; } = new() { "banana" };
    }
}

Properties

Name Type Description Notes Default Value
property icon Checked IValueBinding<Boolean> Binds whether the checkbox is selected in single-value mode.
attribute
inner element
static value
bindable
default
null
property icon CheckedItems IValueBinding<IEnumerable> Binds the collection used in multi-select checkbox scenarios.
attribute
inner element
static value
bindable
default
null
property icon CheckedValue Object Specifies the value added to or removed from the CheckedItems collection.
attribute
inner element
static value
bindable
default
null
property icon Content List<DotvvmControl> Gets or sets custom label content rendered next to the checkbox. Cannot be combined with Text.
attribute
inner element
static value
bindable
default
null
property icon Enabled Boolean Controls whether the checkbox can be interacted with.
attribute
inner element
static value
bindable
default
True
property icon Text String Gets or sets the plain-text label rendered next to the checkbox. Cannot be combined with Content.
attribute
inner element
static value
bindable
default
null
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

Events

Name Type Description
event icon Changed ICommandBinding Runs after the checked state changes.

HTML produced by the control