diff --git a/README.md b/README.md index 4c4e858f8..79960118e 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ There are a significant number of controls in ASP.NET Web Forms, and we will foc - BulletedList - [Button](docs/EditorControls/Button.md) - Calendar - - CheckBox + - [CheckBox](docs/EditorControls/CheckBox.md) - CheckBoxList - DropDownList - FileUpload diff --git a/docs/EditorControls/CheckBox.md b/docs/EditorControls/CheckBox.md new file mode 100644 index 000000000..479061b18 --- /dev/null +++ b/docs/EditorControls/CheckBox.md @@ -0,0 +1,197 @@ +# CheckBox + +The CheckBox component provides a Blazor implementation of the ASP.NET Web Forms CheckBox control, enabling boolean input with an optional text label. + +Original Microsoft documentation: https://docs.microsoft.com/en-us/dotnet/api/system.web.ui.webcontrols.checkbox?view=netframework-4.8 + +## Features Supported in Blazor + +- `Checked` property for boolean state +- `Text` property for label display +- `TextAlign` property (Left or Right) for label positioning +- Two-way binding with `@bind-Checked` +- `OnCheckedChanged` event handler +- `Enabled` property to disable the checkbox +- Style attributes (BackColor, ForeColor, CssClass, etc.) +- `Visible` property to show/hide the checkbox + +## Web Forms Features NOT Supported + +- `AutoPostBack` is not supported in Blazor. Use the `OnCheckedChanged` event instead to react to state changes. +- `InputAttributes` property is not implemented +- `LabelAttributes` property is not implemented + +## Web Forms Declarative Syntax + +```html + +``` + +## Blazor Syntax + +### Basic CheckBox + +```razor + +``` + +### Pre-checked CheckBox + +```razor + +``` + +### Two-way Binding + +```razor + + +@code { + private bool isSubscribed = false; +} +``` + +### Text Alignment + +By default, the label appears to the right of the checkbox. Use `TextAlign` to position it on the left: + +```razor + + +``` + +### Event Handling + +```razor + + +@code { + private void HandleChange(ChangeEventArgs e) + { + bool isChecked = (bool)e.Value; + // Handle the change + } +} +``` + +### Disabled CheckBox + +```razor + +``` + +### Styled CheckBox + +```razor +@using static BlazorWebFormsComponents.WebColor + + +``` + +### CheckBox without Text + +When no `Text` is provided, the checkbox renders without a `` wrapper or `