|
| 1 | +--- |
| 2 | +title: Events |
| 3 | +page_title: Calendar for Blazor | Events |
| 4 | +description: Events in the Calendar for Blazor |
| 5 | +slug: components/calendar/events |
| 6 | +tags: telerik,blazor,calendar,events |
| 7 | +published: true |
| 8 | +position: 20 |
| 9 | +--- |
| 10 | + |
| 11 | +# Events |
| 12 | + |
| 13 | +This article explsins the events available in the Telerik Calendar for Blazor: |
| 14 | + |
| 15 | +* [ValueChanged](#valuechanged) |
| 16 | +* [DateChanged](#datechanged) |
| 17 | +* [ViewChanged](#viewchanged) |
| 18 | + |
| 19 | +## ValueChanged |
| 20 | + |
| 21 | +The `ValueChanged` event fires when the user selects a date. To see how to handle it and to obtain the user selection, review the [Selection]({%slug components/calendar/selection%}) article. |
| 22 | + |
| 23 | +## DateChanged |
| 24 | + |
| 25 | +The `DateChanged` event fires when the currently shown date changes. For example, when the user [navigates]({%slug components/calendar/navigation%}) from one month to the next through the arrows. |
| 26 | + |
| 27 | +When handling the `DateChanged` event, you cannot use two-way binding for the `Date` parameter. You should update it yourself in the model. If you do not, the currently shown range may revert to the original value set in the markup or to the default value. |
| 28 | + |
| 29 | +````CSHTML |
| 30 | +@result |
| 31 | +<br /> |
| 32 | +<TelerikCalendar Min="@min" Max="@max" Date="@initialDate" DateChanged="@DateChangedHandler"> |
| 33 | +</TelerikCalendar> |
| 34 | +
|
| 35 | +@code { |
| 36 | + DateTime initialDate { get; set; } = DateTime.Now; |
| 37 | + DateTime min = new DateTime(2015, 1, 1); |
| 38 | + DateTime max = new DateTime(2025, 12, 31); |
| 39 | + string result { get; set; } |
| 40 | +
|
| 41 | + void DateChangedHandler(DateTime firstDateOfNewRange) |
| 42 | + { |
| 43 | + result = $"the user now sees a range that includes {firstDateOfNewRange}"; |
| 44 | + initialDate = firstDateOfNewRange; // if you don't do this, navigating adjacent ranges will be effectively disabled |
| 45 | + } |
| 46 | +} |
| 47 | +```` |
| 48 | + |
| 49 | +>tip You are not required to provide an initial value to the `Date` parameter. It will default to `DateTime.Now`. |
| 50 | +
|
| 51 | +## ViewChanged |
| 52 | + |
| 53 | +The `ViewChanged` event fires when the user changes the view they are seeing (for example, goes up from the days in the month to the months in the year). |
| 54 | + |
| 55 | +When handling the `ViewChanged` event, you cannot use two-way binding for the `View` parameter. You should update it yourself in the model. If you do not, the currently shown view may revert to the original value set in the markup or to the default value. |
| 56 | + |
| 57 | +````CSHTML |
| 58 | +@result |
| 59 | +<br /> |
| 60 | +<TelerikCalendar Min="@min" Max="@max" View="@initialView" ViewChanged="@ViewChangedHandler"> |
| 61 | +</TelerikCalendar> |
| 62 | +
|
| 63 | +@code { |
| 64 | + CalendarView initialView { get; set; } = CalendarView.Year; |
| 65 | + DateTime min = new DateTime(2015, 1, 1); |
| 66 | + DateTime max = new DateTime(2025, 12, 31); |
| 67 | + string result { get; set; } |
| 68 | +
|
| 69 | + void ViewChangedHandler(CalendarView currView) |
| 70 | + { |
| 71 | + result = $"the user now sees the {currView} view"; |
| 72 | + initialView = currView; // if you don't do this, navigating views will be effectively disabled |
| 73 | + } |
| 74 | +} |
| 75 | +```` |
| 76 | + |
| 77 | +>tip You are not required to provide an initial value to the `View` parameter. It will default to `CalendarView.Month`. |
| 78 | +
|
| 79 | +## See Also |
| 80 | + |
| 81 | +* [Selection]({%slug components/calendar/selection%}) |
| 82 | +* [Navigation]({%slug components/calendar/navigation%}) |
0 commit comments