Skip to content

Commit 0a6f1b1

Browse files
Merge pull request #1112 from telerik/didi/scheduler-non-working-hour-kb
add scheduler non working hours
2 parents ff10615 + f6b9079 commit 0a6f1b1

File tree

4 files changed

+97
-2
lines changed

4 files changed

+97
-2
lines changed

controls/scheduler/appointments/overview.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,5 @@ The image below shows the appointments in WeekView:
3838

3939
- [Appointment Template]({%slug scheduler-appointment-template%})
4040
- [Appointments Styling]({%slug scheduler-appointments-styling%})
41-
- [Recurrence]({%slug scheduler-recurrence-overview %})
41+
- [Recurrence]({%slug scheduler-recurrence-overview %})
42+
- [Non-Working Hours]({%slug scheduler-net-maui-non-working-hours%})

controls/scheduler/specialslots/overview.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,4 @@ Check in the image below how the special slots look in MultiDay View:
4040

4141
- [Special Slots Template]({%slug scheduler-special-slot-template%})
4242
- [Views]({% slug scheduler-views-overview %})
43+
- [Non-Working Hours]({%slug scheduler-net-maui-non-working-hours%})

controls/scheduler/specialslots/special-slot-template.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ Check the image below which shows the applied `SpecialSlotTemplate`:
2929
## See Also
3030

3131
- [Special Slots]({%slug scheduler-special-slots%})
32-
- [Views]({% slug scheduler-views-overview %})
32+
- [Views]({% slug scheduler-views-overview %})
33+
- [Non-Working Hours]({%slug scheduler-net-maui-non-working-hours%})
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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+
When transitioning from the Xamarin Calendar and Scheduler to the 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

Comments
 (0)