Articles in this section
Category / Section

How to move to the required time while switching from month to day view in WinUI Scheduler (Calendar)

2 mins read

In the SfScheduler, move to the required time while switching the scheduler view by using the DisplayDate property in the CellTapped event, which will be fired while tapping the scheduler cell.

XAML

Add Scheduler, to handle the CellTapped handler.

<scheduler:SfScheduler x:Name="Schedule" 
                       ViewType="Month"                              
                       CellTapped="Schedule_CellTapped"/>

C#

In the CellTapped event, set the required SchedulerViewType to be switched. Set the DisplayDate to the schedule with the required hour and date to be moved on tapping the date on the month cell, so that the view changes to that specific date and time in the day view. By setting the current time to the date and subtracting the hours needed from the current time of the day, the time of the day can be positioned in the center of the view while switching from the month view to the day view.

//Event Customization
private void Schedule_CellTapped(object sender, CellTappedEventArgs e)
{
    this.Schedule.ViewType = SchedulerViewType.Day;
 
    DateTime currentDate = DateTime.Now;
    DateTime SpecificDateTime = new DateTime(currentDate.Year, currentDate.Month, currentDate.Day, currentDate.Hour, currentDate.Minute, currentDate.Second);
    var numberOfSecondsPerHour = 3600;
    var requiredHours = 6;
    this.Schedule.DisplayDate = e.DateTime.AddSeconds((SpecificDateTime.Hour - requiredHours) * numberOfSecondsPerHour);
}

Calendar

Description automatically generated

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied