How to highlight working and non working hours in .NET MAUI Scheduler (SfScheduler) days view and timeline view?
In the .NET MAUI Scheduler, you can highlight the timeslots for working and non-working hours using the TimeRegions property of the DaysView and TimelineView. The EnablePointerInteraction property allows you to enable or disable touch interaction. By default, EnablePointerInteraction is set to true.
XAML
Initialize the scheduler with the required properties.
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="WorkHour.MainPage" xmlns:scheduler="clr-namespace:Syncfusion.Maui.Scheduler;assembly=Syncfusion.Maui.Scheduler"> <Grid> <scheduler:SfScheduler x:Name="Scheduler" AllowedViews="Day,Week,WorkWeek,TimelineDay,TimelineWeek,TimelineWorkWeek"/> </Grid> </ContentPage>
CS
Add the required time regions to highlight the working and non-working hours using the method shown below..
public partial class MainPage : ContentPage { public MainPage() { InitializeComponent(); this.Scheduler.View = SchedulerView.Week; this.Scheduler.TimelineView.TimeRegions = this.GetTimeRegion(); this.Scheduler.DaysView.TimeRegions = this.GetTimeRegion(); } private ObservableCollection<SchedulerTimeRegion> GetTimeRegion() { var timeRegions = new ObservableCollection<SchedulerTimeRegion>(); DateTime today = DateTime.Now; Brush background = new SolidColorBrush(Colors.LightGray.WithAlpha(0.3f)); var nonWorkingRegion1 = new SchedulerTimeRegion() { StartTime = new DateTime(today.Year, today.Month, 1, 00, 0, 0), EndTime = new DateTime(today.Year, today.Month, 1, 9, 0, 0), EnablePointerInteraction = false, RecurrenceRule = "FREQ=WEEKLY;INTERVAL=1;BYDAY=MO,TU,WE,TH,FR", Background = background, }; var nonWorkingRegion2 = new SchedulerTimeRegion() { StartTime = new DateTime(today.Year, today.Month, 1, 18, 0, 0), EndTime = new DateTime(today.Year, today.Month, 1, 23, 59, 0), EnablePointerInteraction = false, RecurrenceRule = "FREQ=WEEKLY;INTERVAL=1;BYDAY=MO,TU,WE,TH,FR", Background = background, }; var workingRegion = new SchedulerTimeRegion() { StartTime = new DateTime(today.Year, today.Month, 1, 9, 0, 0), EndTime = new DateTime(today.Year, today.Month, 1, 18, 0, 0), EnablePointerInteraction = true, RecurrenceRule = "FREQ=WEEKLY;INTERVAL=1;BYDAY=MO,TU,WE,TH,FR", Background = new SolidColorBrush(Colors.LightBlue.WithAlpha(0.3f)) }; var nonWorkingDays = new SchedulerTimeRegion() { StartTime = new DateTime(today.Year, today.Month, 1, 0, 0, 0), EndTime = new DateTime(today.Year, today.Month, 1, 23, 59, 0), EnablePointerInteraction = false, Background = background, RecurrenceRule = "FREQ=WEEKLY;INTERVAL=1;BYDAY=SU,SA", }; var lunchBreak = new SchedulerTimeRegion() { StartTime = new DateTime(today.Year, today.Month, 1, 13, 0, 0), EndTime = new DateTime(today.Year, today.Month, 1, 14, 0, 0), EnablePointerInteraction = false, RecurrenceRule = "FREQ=WEEKLY;INTERVAL=1;BYDAY=MO,TU,WE,TH,FR", Background = Brush.Gray, Text = "Lunch", TextStyle = new SchedulerTextStyle { TextColor = Colors.White, FontSize = 10 }, }; var breakFN = new SchedulerTimeRegion() { StartTime = new DateTime(today.Year, today.Month, 1, 10, 0, 0), EndTime = new DateTime(today.Year, today.Month, 1, 10, 30, 0), EnablePointerInteraction = false, RecurrenceRule = "FREQ=WEEKLY;INTERVAL=1;BYDAY=MO,WE,FR", Background = Brush.Gray, Text = "Break", TextStyle = new SchedulerTextStyle { TextColor = Colors.White, FontSize = 10 }, }; var breakAN = new SchedulerTimeRegion() { StartTime = new DateTime(today.Year, today.Month, 1, 16, 0, 0), EndTime = new DateTime(today.Year, today.Month, 1, 16, 30, 0), EnablePointerInteraction = false, RecurrenceRule = "FREQ=WEEKLY;INTERVAL=1;BYDAY=TU,TH", Background = Brush.Gray, Text = "Break", TextStyle = new SchedulerTextStyle { TextColor = Colors.White, FontSize = 10 }, }; timeRegions.Add(nonWorkingRegion1); timeRegions.Add(nonWorkingRegion2); timeRegions.Add(workingRegion); timeRegions.Add(nonWorkingDays); timeRegions.Add(lunchBreak); timeRegions.Add(breakFN); timeRegions.Add(breakAN); return timeRegions; } }
Output
Conclusion
I hope you enjoyed learning how to highlight the working and non working hours in the .NET MAUI Scheduler's days view and timeline view.
Refer to our .NET MAUI Scheduler feature tour page to learn about its other groundbreaking feature representations. You can explore our .NET MAUI Scheduler documentation to understand how to present and manipulate data.
For current customers, check out our .NET MAUI components from the License and Downloads page. If you are new to Syncfusion®, try our 30-day free trial to check out our .NET MAUI Scheduler and other .NET MAUI components.
Please let us know in the following comments section if you have any queries or require clarifications. Contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!