|
| 1 | +--- |
| 2 | +title: Defining Non-Working Hours in Scheduler for .NET MAUI |
| 3 | +description: Learn how to display non-working hours in the Telerik Scheduler for .NET MAUI across DayView, WeekView, and MultiDayView. |
| 4 | +type: how-to |
| 5 | +page_title: Displaying Non-Working Hours in Scheduler Views for .NET MAUI |
| 6 | +slug: scheduler-net-maui-non-working-hours |
| 7 | +tags: scheduler, .net maui, non-working hours, dayview, weekview, multidateview, special slots |
| 8 | +res_type: kb |
| 9 | +--- |
| 10 | + |
| 11 | +## Environment |
| 12 | + |
| 13 | +| Version | Product | Author | |
| 14 | +| --- | --- | ---- | |
| 15 | +| 10.0.0 | Scheduler for .NET MAUI | [Dobrinka Yordanova](https://www.telerik.com/blogs/author/dobrinka-yordanova) | |
| 16 | + |
| 17 | +## Description |
| 18 | + |
| 19 | +In transitioning from Xamarin Calendar and Scheduler to Telerik Scheduler for .NET MAUI, it's essential to know how to define and display non-working hours in DayView, WeekView, and MultiDayView modes. |
| 20 | + |
| 21 | +This knowledge base article also answers the following questions: |
| 22 | +- How can I mark non-working hours in the Telerik Scheduler for .NET MAUI? |
| 23 | +- What approach should I use to display special slots indicating non-working hours in different Scheduler views? |
| 24 | +- How do I configure the Scheduler to show non-working hours using the `SpecialSlots` feature? |
| 25 | + |
| 26 | +## Solution |
| 27 | + |
| 28 | +To display non-working hours in the Telerik Scheduler for .NET MAUI, leverage the [`SpecialSlots`](https://docs.telerik.com/devtools/maui/controls/scheduler/specialslots/overview) feature. This solution involves configuring the Scheduler in the XAML, setting up the `ViewModel` to define non-working hours. Follow the steps below to achieve this. |
| 29 | + |
| 30 | +**1.** Define the Scheduler in XAML with the `SpecialSlotsSource` property for each view to bind to the non-working hours collection. |
| 31 | + |
| 32 | +```xaml |
| 33 | +<Grid> |
| 34 | + <telerik:RadScheduler AppointmentsSource="{Binding Appointments}"> |
| 35 | + <telerik:RadScheduler.ViewDefinitions> |
| 36 | + <telerik:WeekViewDefinition SpecialSlotsSource="{Binding NonWorkingHours}" /> |
| 37 | + <telerik:WeekViewDefinition Title="Work Week" |
| 38 | + IsWeekendVisible="False" |
| 39 | + SpecialSlotsSource="{Binding NonWorkingHours}" /> |
| 40 | + <telerik:MultidayViewDefinition VisibleDays="3" |
| 41 | + Title="3 Day" |
| 42 | + SpecialSlotsSource="{Binding NonWorkingHours}" /> |
| 43 | + <telerik:DayViewDefinition SpecialSlotsSource="{Binding NonWorkingHours}" /> |
| 44 | + </telerik:RadScheduler.ViewDefinitions> |
| 45 | + </telerik:RadScheduler> |
| 46 | +</Grid> |
| 47 | +``` |
| 48 | + |
| 49 | +**2.** Define the `ViewModel` to include a collection of appointments and non-working hours. |
| 50 | +The non-working hours are defined as special slots with a recurrence pattern to repeat weekly. |
| 51 | + |
| 52 | +```C# |
| 53 | +public class ViewModel : NotifyPropertyChangedBase |
| 54 | +{ |
| 55 | + public ViewModel() |
| 56 | + { |
| 57 | + this.Appointments = new ObservableCollection<Appointment>(); |
| 58 | + var now = DateTime.Now; |
| 59 | + // Appointments are added here... |
| 60 | + |
| 61 | + this.NonWorkingHours = new ObservableCollection<Slot>(); |
| 62 | + |
| 63 | + DateTime start = new DateTime(2010, 1, 1, 8, 0, 0); |
| 64 | + DateTime end = new DateTime(2010, 1, 1, 18, 0, 0); |
| 65 | + this.NonWorkingHours.Add(new Slot(end, start.AddDays(1)) |
| 66 | + { |
| 67 | + RecurrencePattern = new RecurrencePattern(null, RecurrenceDays.Monday | RecurrenceDays.Tuesday | RecurrenceDays.Wednesday | RecurrenceDays.Thursday, RecurrenceFrequency.Weekly, 1, null, null) |
| 68 | + }); |
| 69 | + |
| 70 | + this.NonWorkingHours.Add(new Slot(end, start.AddDays(3)) |
| 71 | + { |
| 72 | + RecurrencePattern = new RecurrencePattern(null, RecurrenceDays.Friday, RecurrenceFrequency.Weekly, 1, null, null) |
| 73 | + }); |
| 74 | + } |
| 75 | + |
| 76 | + public ObservableCollection<Appointment> Appointments { get; set; } |
| 77 | + public ObservableCollection<Slot> NonWorkingHours { get; set; } |
| 78 | +} |
| 79 | +``` |
| 80 | + |
| 81 | +**3.** Set the binding context of your page to the `ViewModel` to ensure the Scheduler is bound to the appropriate data. |
| 82 | + |
| 83 | +```C# |
| 84 | +this.BindingContext = new ViewModel(); |
| 85 | +``` |
| 86 | + |
| 87 | +By following these steps, the Telerik Scheduler for .NET MAUI will display non-working hours as specified in the `ViewModel`, across day view, week view, and multi day view definitions. This approach effectively utilizes the SpecialSlots feature to highlight non-working hours, enhancing the scheduler's functionality and user experience. |
| 88 | + |
| 89 | +## See Also |
| 90 | + |
| 91 | +- [Scheduler Special Slots Overview](https://docs.telerik.com/devtools/maui/controls/scheduler/specialslots/overview) |
| 92 | +- [Scheduler for .NET MAUI Documentation](https://docs.telerik.com/devtools/maui/controls/scheduler/overview) |
0 commit comments