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

RecurrenceRule

RadScheduleView 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 correct RecurrencePattern.

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

The purpose of this tutorial is to show you:

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 RecurrenceRule class is located in the Telerik.Windows.Controls.ScheduleView namespace of the Telerik.Windows.Controls.ScheduleView.dll assembly.

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.

var startDate = new DateTime(2011, 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); 
Dim startDate = New DateTime(2011, 5, 11, 10, 0, 0) 
Dim fitnessAppointment = New Appointment() With { 
    .Start = startDate, 
    .[End] = startDate.AddHours(2), 
    .Subject = "Fitness" 
} 
Dim recurrencePattern = New RecurrencePattern() With { 
    .Frequency = RecurrenceFrequency.Weekly, 
    .MaxOccurrences = 30, 
    .DaysOfWeekMask = RecurrenceDays.Monday Or RecurrenceDays.Wednesday Or 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

RadScheduleView'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.

var startDate = new DateTime(2011, 05, 11, 10, 0, 0); 
var fitnessAppointment = new Appointment() 
{ 
    Start = startDate, 
    End = startDate.AddHours(2), 
    Subject = "Fitness" 
}; 
Dim startDate = New DateTime(2011, 5, 11, 10, 0, 0) 
Dim fitnessAppointment = New Appointment() With { 
    .Start = startDate, 
    .[End] = startDate.AddHours(2), 
    .Subject = "Fitness" 
} 

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

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

var exceptionDate = fitnessAppointment.Copy() 
exceptionDate.Start = fitnessAppointment.Start.AddDays(-1); 
exceptionDate.End = fitnessAppointment.End.AddDays(-1);           
rule.AddException(startDate, exceptionDate); 
Dim 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.

fitnessAppointment.RecurrenceRule = rule; 
fitnessAppointment.RecurrenceRule = rule 

When adding the created appointment to the RadScheduleView's AppointmentsSource collection the result should be similar to the snapshot below.

WPF RadScheduleView Recurrence Rule

In this article