All docs
V20.1
20.2 (EAP/Beta)
20.1
19.2
19.1
The page you are viewing does not exist in version 19.1. This link will take you to the root page.
18.2
The page you are viewing does not exist in version 18.2. This link will take you to the root page.
18.1
The page you are viewing does not exist in version 18.1. This link will take you to the root page.
17.2
The page you are viewing does not exist in version 17.2. This link will take you to the root page.

How to: Create Regular and Recurrent Appointments at the View Model Level

  • 2 minutes to read

This example illustrates how to add a new regular or recurrent appointment programmatically when the Scheduler is in bound mode.

IMPORTANT

It's essential that your data source type implements the INotifyCollectionChanged (e.g., ObservableCollection<T>). In this case, the Scheduler Control will receive notifications about its changes.

To add a new appointment, create a new data item instance, define its properties, and add it to your source. In this example, SchedulerControl's SelectedInterval property is bound to the Interval property from the view model. Its values are used in the data item's Start and End properties:

protected ApptViewModel CreateAppt(string subj, DateTime start, DateTime end, string description) {
    ApptViewModel apptViewModel = new ApptViewModel() {
        Subject = subj,
        Start = start,                
        End = end,
        Description = "[add description]"
    };
    return apptViewModel;
}

Set the item's Type property to AppoinementType.Pattern and define a corresponding recurrence rule in the RecurrenceInfo property to create a recurrent appointment. Use RecurrenceBuilder to generate this rule:

[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;
    }

    this.Appointments.Add(appt);
    this.SelectedAppointments.Clear();
    this.SelectedAppointments.Add(appt);
}

Refer to the How to: Create Recurrence in Code article for more information about generating recurrence rules.

This example also illustrates how you can invoke EditAppointmentWindow for a newly created appointment. This functionality is implemented with the help of the CompositeCommandBehavior class. The first CommandItem's Command property is bound to a property from the view model. The second CommandItem's Command is bound to SchedulerControl's Commands.ShowAppointmentWindowCommand command:

<dxb:BarButtonItem Content="Add a regular appointment">
    <dxmvvm:Interaction.Behaviors>
        <dxmvvm:CompositeCommandBehavior CanExecuteCondition="AnyCommandCanBeExecuted">
            <dxmvvm:CommandItem Command="{Binding AddApptCommand}"
                                CommandParameter="false" />
            <dxmvvm:CommandItem CheckCanExecute="False"
                                Command="{Binding ElementName=scheduler,
                                                  Path=Commands.ShowAppointmentWindowCommand}" />
        </dxmvvm:CompositeCommandBehavior>
    </dxmvvm:Interaction.Behaviors>
</dxb:BarButtonItem>