事件
这篇文章解释了Blazor的Telerik DateInput中可用的事件:
OnChange
的OnChange
事件表示用户操作—确认当前值。它在用户按下时触发输入
在输入中,或者当输入失去焦点时。
日期输入是一个通用组件,因此必须提供价值
的类型T
组件参数。
处理OnChange
@result
@code {string result;private void MyOnChangeHandler(object theUserInput){//处理程序接收到一个你可能需要转换为组件类型的对象//如果你不提供Value,你必须提供type参数给组件result = string。格式("用户输入:{0:dd/MMM/yyyy}", (DateTime)theUserInput);}}
这个事件是
EventCallback
它可以是同步的(返回无效
),或者它也可以是异步的并返回异步任务
.
的
OnChange
Event是自定义事件,不影响绑定,因此可以与模型和表单一起使用。
处理OnChange并使用双向绑定
@result
模型值:@theInputValue
@code {string result;DateTime吗?theInputValue {get;设置;} = DateTime.Now;private void MyOnChangeHandler(object theUserInput){//处理程序接收到一个你可能需要转换为组件类型的对象//如果你不提供Value,你必须提供type参数给组件result = string。格式("用户输入:{0:dd/MMM/yyyy}", (userinput as DateTime?).Value);}}
ValueChanged
的ValueChanged
事件在输入中的每次更改(例如击键)时触发。
处理ValueChanged
@result
@code {string result;private void MyValueChangeHandler(DateTime theUserInput) {result = string。格式("用户输入:{0}",theUserInput);}}
这个事件是
EventCallback
它可以是同步的(返回无效
),或者它也可以是异步的并返回异步任务
.
处理程序中的lambda表达式是框架所需要的:https://github.com/aspnet/AspNetCore/issues/12226.
处理ValueChanged并提供初始值
@result
模型值:@ theinputvalue
@code {string result;DateTime设置;} = DateTime.Now;private void MyValueChangeHandler(DateTime theUserInput) {result = string。格式("用户输入:{0:dd/MMM/yyyy}", theUserInput);//你必须手动更新模型,因为处理ValueChanged事件不允许你使用@bind-Value theInputValue = theUserInput;}}
元素失去焦点时
的元素失去焦点时
事件在组件失去焦点时触发。
处理OnBlur事件
@*您不必使用OnChange来对焦点丢失做出反应*@ @code{async任务OnBlurHandler(){控制台。WriteLine($"BLUR触发,当前值为{TheDate}.");} DateTime吗?date {get;设置;} = DateTime.Now;}