New to Telerik UI for WinUI? Download free 30-day trial

RecurrenceRule

RadScheduler includes support for recurring events on daily, weekly, monthly and yearly basis. Exceptions to the recurrence rules are also permitted. To support this recurrence behavior, the IAppointment interface includes the RecurrenceRule property. When an appointment is promoted into a recurring event its RecurrenceRule is set with the correct RecurrencePattern.

The RecurrenceRule class is the engine for creating and evaluating recurrence rules.

RecurrenceRule Class

While the RecurrencePattern class carries the main information about the occurrence, the RecurrenceRule class is the engine for creating and evaluating recurrence rules.

The next several sections describe which are the main properties and methods exposed by the RecurrenceRule class.

RecurrencePattern

The RecurrenceRule class exposes a RecurrencePattern property, which allows you to get\set the recurrence pattern associated with the current rule. For more information about the RecurrencePattern, take a look at the RecurrencePattern topic, which is entirely dedicated to recurrence patterns.

Exceptions

The RecurrenceRule class exposes an Exceptions property, which allows you to get or set all exception occurrences associated with the current rule. For more information read How to Add Exception Occurrences to the Recurrence Rule

How to Create a Recurrence Rule and Associate it With an Appointment

The RecurrenceRule class has only one public constructor, which accepts a RecurrencePattern as a parameter.

The RecurrencePattern is a mandatory part of the RecurrenceRule. Which means that when creating a new RecurrenceRule you must associate the rule with a recurrence pattern.

Example 1: Creating a Recurrence Rule

var startDate = new DateTime(2021, 05, 11, 10, 0, 0); 
var fitnessAppointment = new Appointment() 
{ 
    Start = startDate, 
    End = startDate.AddHours(2), 
    Subject = "Fitness" 
}; 
var recurrencePattern = new RecurrencePattern() 
{ 
    Frequency = RecurrenceFrequency.Weekly, 
    MaxOccurrences = 30, 
    DaysOfWeekMask = RecurrenceDays.Monday | RecurrenceDays.Wednesday | RecurrenceDays.Friday 
};         
fitnessAppointment.RecurrenceRule = new RecurrenceRule(recurrencePattern); 
The above example shows you how to create a recurrence pattern, then how to associate it with a recurrence rule. Finally the recurrence rule is assigned to an appointment.

How to Add Exception Occurrences to the Recurrence Rule

RadScheduler's API permits you to add exception occurrences to the recurrence rule. In order to add exceptions, you should use the RecurrenceRule's AddException() method. The AddException() method has two overloads.

The first one takes two parameters:

  • The first parameter is a DateTime which indicates when the exception occurs.

  • The second parameter is an IAppointment instance. This is the exception appointment.

When you want to add an exception to a recurrence you need to use this method.

The second overload takes only one argument - a DateTime parameter. The purpose of this overload is to add an exception by removing a given occurrence from a recurrence.

One possible scenario of adding an exception to a recurrence rule is shown in the next example:

  • Create a new appointment.

Example 2: Creating a new appointment

var startDate = new DateTime(2021, 05, 11, 10, 0, 0); 
var fitnessAppointment = new Appointment() 
{ 
    Start = startDate, 
    End = startDate.AddHours(2), 
    Subject = "Fitness" 
}; 

Example 3: Creating a RecurrencePattern

var recurrencePattern = new RecurrencePattern() 
{ 
    Frequency = RecurrenceFrequency.Daily, 
    DaysOfWeekMask = RecurrenceDays.Wednesday, 
    MaxOccurrences = 10 
}; 
  • Create a RecurrenceRule and associate the create recurrence pattern with it.

Example 4: Creating a RecurrenceRule

var rule = new RecurrenceRule(recurrencePattern); 
  • Add an exception occurrence to the recurrence rule.

Example 5: Adding an exception occurrence

var exceptionDate = fitnessAppointment.Copy() 
exceptionDate.Start = fitnessAppointment.Start.AddDays(-1); 
exceptionDate.End = fitnessAppointment.End.AddDays(-1);           
rule.AddException(startDate, exceptionDate); 
  • Associate the create recurrence rule with the appointment.

Example 6: Setting the RecurrenceRule

fitnessAppointment.RecurrenceRule = rule; 
When adding the created appointment to the RadScheduler's AppointmentsSource collection the result should be similar to the snapshot below.

Figure 1: Recurrent appointment

WinUI Recurrent appointment

In this article
Not finding the help you need?