为Blazor的Telerik UI?下载30天免费试用

事件

这篇文章解释了在开拓者的Telerik日历中可用的事件:

ValueChanged

ValueChanged事件在用户选择日期时触发。要了解如何处理它并获取用户选择,请查看选择篇文章。

集中DateChanged

集中DateChanged事件在当前显示的日期更改时触发。例如,当用户导航通过箭头从一个月到下一个月。

处理集中DateChanged事件时,不能对日期参数。您应该在模型中自己更新它。如果不这样做,则当前显示的范围可能恢复到标记中设置的原始值或默认值。

@EventLog 
@code {private DateTime CalendarDate {get;设置;} = DateTime.Now;private DateTime CalendarMin {get;设置;} = DateTime.Now.AddYears(-5);private DateTime CalendarMax {get;设置;} = DateTime.Now.AddYears(5);private string EventLog {get; set; } private void OnCalendarDateChanged(DateTime newDate) { CalendarDate = newDate; EventLog = $"The user sees a range that includes {newDate}"; } }

控件的初始值不需要提供日期参数。它会默认为DateTime。现在

ViewChanged

ViewChanged事件在用户更改他们所看到的视图时触发(例如,从每月的天数上升到每年的月份)。

处理ViewChanged事件时,不能对视图参数。您应该在模型中自己更新它。如果不这样做,则当前显示的视图可能恢复到标记中设置的原始值或默认值。

@result 
@code {CalendarView initialView {get;设置;} = CalendarView.Year;DateTime min = new DateTime(2015, 1,1);DateTime max = new DateTime(2025, 12,31);字符串结果{get;设置;} void ViewChangedHandler(CalendarView currView) {result = $"用户现在看到{currView}视图";initialView = currView;//如果你不这样做,导航视图将被有效禁用}}

控件的初始值不需要提供视图参数。它会默认为CalendarView。月

RangeStartChanged和RangeEndChanged

两个RangeChanged事件(RangeStartChangedRangeEndChanged)触发时,用户选择一个新的范围。

当用户从日历中选择一个范围时,第一次单击总是触发带有所选日期的开始更改,然后清除范围的结束,因此结束更改事件也会触发,其默认值为DateTime-这表示范围的结束未定义。如果第二次点击是在范围开始之前的日期上,它将成为新的开始。

的例子范围选择与RangeStartChangedRangeEndChanged事件

观察RangeStartChanged和RangeEndChanged事件的行为,并将选中的日期添加到列表中。范围" RangeStart="@RangeStart" RangeEnd="@RangeEnd" RangeStartChanged="@StartChangeHandler" RangeEndChanged="@EndChangeHandler">  @if (SelectedDates.Any()) { 
Selected dates:
@foreach (var day in SelectedDates) {

@day

}
} @code { DateTime Date { get; set; } = DateTime.Now.AddDays(-5); DateTime RangeStart { get; set; } = DateTime.Now; DateTime RangeEnd { get; set; } = DateTime.Now.AddDays(6); List SelectedDates { get; set; } = new List(); void StartChangeHandler(DateTime startDate) { // you have to update the model manually because handling the Changed event does not let you use @bind- // not updating the model will effectively cancel the event RangeStart = startDate; Console.WriteLine($"The user started making a new selection from {startDate}"); RenderDateRange(); } void EndChangeHandler(DateTime endDate) { // you have to update the model manually because handling the Changed event does not let you use @bind- // not updating the model will effectively cancel the event RangeEnd = endDate; // sample check to execute logic only after the user has selected both ends of the range // if this does not pass, the user has only clicked once in the calendar popup if (endDate != default(DateTime)) { Console.WriteLine($"The user finished making a new selection from {RangeStart} to {endDate}"); } RenderDateRange(); } void RenderDateRange() { var datesInBetween = Enumerable.Range(0, 1 + RangeEnd.Subtract(RangeStart).Days) .Select(offset => RangeStart.AddDays(offset)) .ToList(); SelectedDates = datesInBetween; } }

CellRender

CellRender事件在每个视图中的每个单元格即将呈现时触发。该事件允许您查找当前视图和单元格日期。类的自定义CSS类< td >元素。

事件参数是类型的CalendarCellRenderEventArgs并提供以下字段:

财产 类型 描述
字符串 cell DOM元素的自定义CSS类。
日期 DateTime 单元格的日期
视图 CalendarView枚举
当前可见的视图。您可以使用它来确定日历是否呈现MonthView、YearView等。

您还可以通过它们自定义单元格模板.您可以将该事件与模板一起使用。

使用CellRender事件根据条件设置单元格样式

在日历视图之间移动,以查看Month和Decade视图中的不同行为。  @code {private void OnCellRender(CalendarCellRenderEventArgs args) {if (args。View == CalendarView.Month) {args.Class = args.Date.Day % 3 == 0 ?“特殊”:“”;} else if (args.}视图== CalendarView.Decade) { args.Class = args.Date.Year == 2020 ? "special" : ""; } } } 

上面代码片段的结果

单元格渲染外观定制

另请参阅

在本文中
Baidu
map