wpf-119648-controls-and-libraries-scheduler-examples-how-to-create-recurrence-in-code.md
This section demonstrates how to create recurring appointments in code which have different periodicity and number of occurrences.
Perform the following steps:
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:
[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;
}
...
}
<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.