Class TwDateTimePicker
- Namespace
- TwBlazor.Components
- Assembly
- TwBlazor.dll
Represents a date and time picker component that allows users to select and edit date and time values, supporting both 12-hour and 24-hour formats.
public class TwDateTimePicker : TwBlazorTextInputComponentBase, IComponent, IHandleEvent, IHandleAfterRender, ITwComponent, ITwInputComponent, IAsyncDisposable
- Inheritance
-
TwDateTimePicker
- Implements
- Inherited Members
Remarks
Use the TwDateTimePicker component to provide an interactive UI for selecting date and time values in Blazor applications. The component supports two-way binding for both the selected DateTime value and its string representation, and can be configured to display time in either 12-hour (AM/PM) or 24-hour format. The placeholder text can be customized to guide users when no value is selected.
Constructors
TwDateTimePicker()
public TwDateTimePicker()
Properties
Format
The .NET custom date/time format string used to display and parse SelectedDateTime. Leave unset to fall back to DefaultDateTimeFormat or DefaultDateTimeFormat12Hour depending on Is12HourFormat.
[Parameter]
public string? Format { get; set; }
Property Value
Is12HourFormat
Gets or sets a value indicating whether the time should be displayed in 12-hour format.
[Parameter]
public bool? Is12HourFormat { get; set; }
Property Value
- bool?
Remarks
Set this property to true to use 12-hour time representation (with AM/PM); otherwise, 24-hour format will be used. Has no effect when Format is explicitly set.
Placeholder
The placeholder text to display when no date is selected. Defaults to the localized DateTimePicker_Placeholder text ("Select a datetime").
[Parameter]
public string? Placeholder { get; set; }
Property Value
PreferNativePicker
Overrides automatic device detection for whether the browser's native datetime picker should be used instead of the custom popover. Leave unset (null) to auto-detect based on the client platform (iOS and Android use the native picker by default).
[Parameter]
public bool? PreferNativePicker { get; set; }
Property Value
- bool?
SelectedDateTime
The selected DateTime value.
[Parameter]
public DateTime SelectedDateTime { get; set; }
Property Value
SelectedDateTimeChanged
The selected bound DateTime value.
[Parameter]
public EventCallback<DateTime> SelectedDateTimeChanged { get; set; }
Property Value
SelectedDateTimeExpression
Gets or sets the expression that identifies the bound date and time. Set automatically by
@bind-SelectedDateTime, it lets an enclosing EditForm or TwForm validate
the property the field edits.
[Parameter]
public Expression<Func<DateTime>>? SelectedDateTimeExpression { get; set; }
Property Value
Step
Gets or sets the step, in minutes, that the time step buttons and Arrow Up/Arrow Down move the time by. Steps under an hour move the minutes (e.g. 15 gives :00, :15, :30, :45); steps of an hour or more move the hours (e.g. 120 steps two hours at a time) and the minutes show as fixed text. Must divide an hour or, for whole hours, a day. Defaults to 1. Typed times are not rounded to the step.
[Parameter]
public int Step { get; set; }
Property Value
Value
The string value displayed in the textbox to the user.
[Parameter]
public string? Value { get; set; }
Property Value
ValueChanged
The string bound value displayed in the textbox to the user.
[Parameter]
public EventCallback<string> ValueChanged { get; set; }
Property Value
ValueExpression
Gets or sets the expression that identifies the bound text. Set automatically by @bind-Value, it
lets an enclosing EditForm or TwForm validate the property the field edits.
[Parameter]
public Expression<Func<string?>>? ValueExpression { get; set; }
Property Value
participatesInForm
Gets whether the field connects to the enclosing form itself. It never does: the date picker it is built on connects for it, using this field's bindings.
protected override bool participatesInForm { get; }
Property Value
Methods
BuildRenderTree(RenderTreeBuilder)
Renders the component to the supplied RenderTreeBuilder.
protected override void BuildRenderTree(RenderTreeBuilder __builder)
Parameters
__builderRenderTreeBuilder
OnParametersSet()
Invoked when the component's parameters have been set. Ensures that the component has a unique identifier by generating one if none is provided.
protected override void OnParametersSet()
Remarks
If the component's identifier is not set, a unique ID is generated based on the component's type name (with a 'Tw' prefix removed if present) and a GUID. This helps ensure that each component instance can be uniquely identified, which is useful for scenarios such as associating labels with form elements or targeting elements in client-side scripts.