DwsCheckBox
API ReferenceCommon patterns
Notification settings
One checkbox per channel, each bound to its own field. Security alerts are required: the box is checked and Disabled, so it is dimmed and out of the tab order, and its Tooltip says why. Marketing consent is managed by an administrator: ReadOnly keeps it focusable and readable, but a click does not change it.
Show Code
CheckBox.razor
<div class="d-flex flex-column gap-1">
<DwsCheckBox Name="CheckBoxDemo_Notify_Email" Label="Email" @bind-Checked="_notifyEmail" />
<DwsCheckBox Name="CheckBoxDemo_Notify_Push" Label="Push notification on this device" @bind-Checked="_notifyPush" />
<DwsCheckBox Name="CheckBoxDemo_Notify_Sms" Label="Text message (SMS)" @bind-Checked="_notifySms" />
<DwsCheckBox Name="CheckBoxDemo_Notify_Security" Label="Security alerts (required)" Checked="true" Disabled="true"
Tooltip="Always sent: we tell you about every new sign-in." />
<DwsCheckBox Name="CheckBoxDemo_Notify_Marketing" Label="Product news and offers (managed by your administrator)"
@bind-Checked="_notifyMarketing" ReadOnly="true" />
</div>
<DwsTypography Name="CheckBoxDemo_Notify_Summary" Typography="DwsTypographyType.Caption" Class="mt-2">@NotificationSummary</DwsTypography>CheckBox.razor.cs
private bool? _notifyEmail = true;
private bool? _notifyPush = false;
private bool? _notifySms = false;
private bool? _notifyMarketing = true;
private string NotificationSummary
{
get
{
List<string> channels = [];
if (_notifyEmail == true) channels.Add("Email");
if (_notifyPush == true) channels.Add("Push");
if (_notifySms == true) channels.Add("SMS");
return channels.Count == 0
? "Only security alerts reach you."
: $"You are notified by: {string.Join(", ", channels)}";
}
}Reference
A colour per state
By default the box uses the text colour. Color sets the colour of the checked state, UnCheckedColor that of the unchecked state - a backup that is not verified yet shows red - and IndeterminateColor that of the mixed state (Warning by default).
Show Code
CheckBox.razor
<div class="d-flex flex-column gap-1">
<DwsCheckBox Name="CheckBoxDemo_Color_Done" Label="Task done" Color="DwsColor.Success" @bind-Checked="_taskDone" />
<DwsCheckBox Name="CheckBoxDemo_Color_Backup" Label="Backup verified" Color="DwsColor.Success" UnCheckedColor="DwsColor.Error" @bind-Checked="_backupVerified" />
<DwsCheckBox Name="CheckBoxDemo_Color_Release" Label="Release checklist" IndeterminateColor="DwsColor.Info" @bind-Checked="_releaseChecklist">
<DwsCheckBox Name="CheckBoxDemo_Color_Tests" Label="All tests passed" @bind-Checked="_releaseTests" />
<DwsCheckBox Name="CheckBoxDemo_Color_Changelog" Label="Changelog written" @bind-Checked="_releaseChangelog" />
</DwsCheckBox>
</div>CheckBox.razor.cs
private bool? _taskDone = true;
private bool? _backupVerified = false;
// Starts mixed: one of the two children is checked.
private bool? _releaseChecklist;
private bool? _releaseTests = true;
private bool? _releaseChangelog = false;Appearance, size, icons and label position
Appearance draws the box as Standard (the icon itself), Filled or Outline, and Size scales it. CheckedIcon and UncheckedIcon replace the glyphs - a star for favourites, a bookmark for reading lists. LabelPositionAtStart puts the label before the box.
Show Code
CheckBox.razor
<div class="d-flex flex-wrap gap-4">
<DwsCheckBox Name="CheckBoxDemo_Appearance_Standard" Label="Standard" Color="DwsColor.Primary" @bind-Checked="_appearanceStandard" />
<DwsCheckBox Name="CheckBoxDemo_Appearance_Filled" Label="Filled" Color="DwsColor.Primary" Appearance="DwsAppearance.Filled" @bind-Checked="_appearanceFilled" />
<DwsCheckBox Name="CheckBoxDemo_Appearance_Outline" Label="Outline" Color="DwsColor.Primary" Appearance="DwsAppearance.Outline" @bind-Checked="_appearanceOutline" />
</div>
<div class="d-flex flex-wrap align-items-center gap-4 mt-3">
@foreach (DwsSize size in _sizes)
{
<DwsCheckBox Name="@($"CheckBoxDemo_Size_{size}")" Label="@size.ToString()" Size="size" Checked="true" />
}
</div>
<div class="d-flex flex-wrap gap-4 mt-3">
<DwsCheckBox Name="CheckBoxDemo_Icon_Favourite" Label="Add to favourites" CheckedIcon="@Icons.BS.StarFill" UncheckedIcon="@Icons.BS.Star"
Color="DwsColor.RatingStar" @bind-Checked="_favourite" />
<DwsCheckBox Name="CheckBoxDemo_Icon_Bookmark" Label="Read later" CheckedIcon="@Icons.BS.BookmarkFill" UncheckedIcon="@Icons.BS.Bookmark"
Color="DwsColor.Primary" @bind-Checked="_readLater" />
<DwsCheckBox Name="CheckBoxDemo_LabelStart" Label="Keep me signed in" LabelPositionAtStart="true" @bind-Checked="_keepSignedIn" />
</div>CheckBox.razor.cs
private static readonly DwsSize[] _sizes = [DwsSize.Small, DwsSize.Medium, DwsSize.Large];
private bool? _appearanceStandard = true;
private bool? _appearanceFilled = true;
private bool? _appearanceOutline = true;
private bool? _favourite = true;
private bool? _readLater = false;
private bool? _keepSignedIn = false;Interface-Description
| Name | Typ | Parameters | Description |
|---|---|---|---|
| AddChild | Task AddChild(DwsCheckBox child) | Registers a child checkbox in a nested checkbox hierarchy. | |
| RemoveChild | Task RemoveChild(DwsCheckBox child) | Removes a child checkbox from a nested checkbox hierarchy. |
| Name | Typ | Default | Description |
|---|---|---|---|
| Checked | bool? | false | Current checked state. null is the mixed (indeterminate) state: aria-checked="mixed" and the indeterminate icon, also on a checkbox without child checkboxes. It stays null until the box is clicked (which checks it); a null value is never reported as a change by itself. |
| CheckedExpression | Expression<Func<bool?>>? | null | The bound field, set by @bind-Checked. Gives the input its name attribute (Model.AcceptTerms, value="true") so a statically rendered form posts it and [SupplyParameterFromForm] binds it. |
| Color | DwsColor | DwsColor.Text | Color used for checked state rendering. |
| UnCheckedColor | DwsColor | DwsColor.Text | Color used for unchecked state rendering. |
| IndeterminateColor | DwsColor | DwsColor.Warning | Color used when the checkbox is in the indeterminate (null) state. |
| CheckedIcon | string | Icons.BS.CheckSquareFill | Icon rendered for the checked state. |
| UncheckedIcon | string | Icons.BS.Square | Icon rendered for the unchecked state. |
| IndeterminateIcon | string | Icons.BS.DashSquareFill | Icon rendered for the indeterminate state. |
| Label | string | string.Empty | Text label displayed with the checkbox. |
| LabelPositionAtStart | bool | false | When true, label is rendered before the checkbox control. |
| ReadOnly | bool | false | When true, checkbox value cannot be changed by user interaction. |
| BoxClass | string? | null | CSS class(es) of the box itself (the span around the input and its icon). Class goes on the component's root since 0.1.5 (breaking: it used to land on this box, so Class="mt-2" moved the box away from its own label); move box styling from Class to BoxClass. |
| Haptic | DwsHapticFeedback | DwsHapticFeedback.Selection | Tactile feedback played inside the tap while the app has haptics switched on. Not played while disabled, read-only or armed for permission selection. |
| KeyboardEnabled | bool | true | When false, removes the checkbox from the keyboard tab order. |
| Size | DwsSize | DwsSize.Medium | Visual size of the checkbox control. |
| Appearance | DwsAppearance | DwsAppearance.None | Visual appearance of the checkbox icon (e.g. Filled, Outline). |
| Tooltip | string | string.Empty | Tooltip text shown on hover. |
| TooltipPosition | DwsTooltipPosition | DwsTooltipPosition.Top | Kept so existing markup still compiles: the tooltip is the browser's native title, which has no position. |
| ChildContent | RenderFragment? | null | Optional nested child checkboxes/content. |
| Name | Typ | Description |
|---|---|---|
| CheckedChanged | EventCallback<bool?> | Fired when the checked value changes. |
| Name | Typ | Default | Description |
|---|---|---|---|
| Element | ElementReference | The associated web component. May be null if accessed before the component is rendered. | |
| ComponentGuid | Guid | Unique identifier for the component. | |
| TypeString | string | The name of the component type, obtained from reflection. | |
| Authorized_RegisterEnabled | bool | false | Indicates whether this component is enabled through a permission registry. |
| Authorized_RegisterSelected | bool | false | Indicates whether this component is selected in permission selection mode. |
| GetInitializedState | bool | false | Returns whether the component is initialized. |
| GetRenderModeState | DwsRenderMode | Returns the current render mode. | |
| GetComponentState | DwsComponentStateType | Returns the current component state. | |
| GetIsInteractiveState | bool | false | Returns whether the component is interactive. |
| GetIsPrerenderingState | bool | false | Returns whether the component is prerendering. |
| GetComponentLoadingState | bool | false | Returns whether the component is loading. |
| IsFormBusy | bool | false | Whether the DwsForm (or DwsFormBusyRegion) around the component is locked because its submit handler is running. The state itself is the cascaded FormBusyState (IDwsFormBusyState). |
| Name | Typ | Parameters | Description |
|---|---|---|---|
| DebugInfo | void | Logs debug information about the component. | |
| UpdateState | void | Updates the component's state and triggers StateHasChanged. | |
| UpdateStateAsync | Task | Asynchronously updates the component's state and triggers StateHasChanged. | |
| Dispose | void | Disposes the component and releases resources. | |
| FocusAsync | ValueTask | bool containedInScrollableList | Sets focus to the component's element. |
| Name | Typ | Default | Description |
|---|---|---|---|
| Name | string | Required unique identifier for the component within its container. | |
| Visible | bool | true | Determines if the component is visible in the UI. |
| Disabled | bool | false | Disables the form control, ensuring it doesn't participate in form submission. |
| ComponentNameSpace | string | The namespace for permission-based access control. | |
| PermissionKey | string? | null | A stable key that takes the place of Name in the generated permission namespace (Page.PermissionKey): the stored permission survives a rename, and components that share a key share one permission entry. Null: keyed by Name. Read once, when the component registers; an explicit ComponentNameSpace wins. |
| Class | string | CSS class(es) of the component's root (the container around label and box). Use BoxClass for the box. | |
| Style | string | Optional in-line styles. | |
| Tag | object | An optional user-defined object to store any additional data with the component. | |
| BackReference | DwsReference | A reference to the enclosing component. | |
| ID | string | The HTML ID attribute for the component. | |
| AdditionalAttributes | Dictionary<string, object> | Further attributes of the checkbox <input> (aria-describedby, data-*, an id), the element they describe. | |
| IgnorePermissionChecks | bool | false | Bypasses all permission checks for this component. |
| IgnorePermissionSelection | bool | false | Ignore permission selection mode for this component. |
| IgnoreFormBusy | bool | false | Takes the component out of the submit lock of the DwsForm (or DwsFormBusyRegion) around it: IsFormBusy stays false for it. |
| Name | Typ | Description |
|---|---|---|
| OnInitializedCallbackStarted | EventCallback | Callback when OnInitialized starts. |
| OnInitializedCallback | EventCallback | Callback during OnInitialized. |
| OnInitializedCallbackCompleted | EventCallback | Callback when OnInitialized completes. |
| OnInitializedAsyncCallbackStarted | EventCallback | Callback when OnInitializedAsync starts. |
| OnInitializedAsyncCallback | EventCallback | Callback during OnInitializedAsync. |
| OnInitializedAsyncCallbackCompleted | EventCallback | Callback when OnInitializedAsync completes. |
| OnIsComponentLoadingChanged | EventCallback<bool> | Callback when IsComponentLoading changes. |
| OnCurrentRenderModeChanged | EventCallback<DwsRenderMode> | Callback when CurrentRenderMode changes. |
| OnComponentStateChanged | EventCallback<DwsComponentStateType> | Callback when ComponentState changes. |
