Back to Devexpress

How to: Create Recurrence in Code

wpf-119648-controls-and-libraries-scheduler-examples-how-to-create-recurrence-in-code.md

latest3.5 KB
Original Source

How to: Create Recurrence in Code

  • Feb 14, 2020
  • 2 minutes to read

This section demonstrates how to create recurring appointments in code which have different periodicity and number of occurrences.

Perform the following steps:

  1. Create a new AppointmentItem of the AppointmentType.Pattern type.
  2. Specify its recurrence information using the AppointmentItem.RecurrenceInfo property.
  3. Add an appointment to the SchedulerControl.AppointmentItems collection.

The following examples show how to create appointments with different recurrence types:

You can create recurring time regions in the same manner.

When the Scheduler is in bound mode, you can define a recurrence rule at the view model level. To do this, update the target data item’s property mapped to AppointmentItem.RecurrenceInfo with a corresponding recurrence rule info information. Use the RecurrenceInfo’s ToXML method to save this rule as a string:

csharp
[Command]
public void AddAppt(bool recurrent = false) {
    var appt = CreateAppt($"New Appt #{Appointments.Count}", Interval.Start, Interval.End, "[add description]");

    if(recurrent) {
        appt.Type = (int)AppointmentType.Pattern;
        appt.RecurrenceInfo = RecurrenceBuilder.Daily(Interval.Start, 10).Build().ToXml();
    } else {
        appt.Type = (int)AppointmentType.Normal;
    }
    ...
}
vb
<Command>
Public Sub AddAppt(Optional ByVal recurrent As Boolean = False)
    Dim appt = CreateAppt($"New Appt #{Appointments.Count}", Interval.Start, Interval.End, "[add description]")

    If recurrent Then
        appt.Type = CInt(Math.Truncate(AppointmentType.Pattern))
        appt.RecurrenceInfo = RecurrenceBuilder.Daily(Interval.Start, 10).Build().ToXml()
    Else
        appt.Type = CInt(Math.Truncate(AppointmentType.Normal))
    End If
    ...
End Sub

Refer to the How to: Create Regular and Recurrent Appointments at the View Model Level example for more information.