/wpf-scheduler-create-regular-and-recurring-appointments-at-view-model-level

Define View Model commands that add new regular and recurrent appointments to the Scheduler Control.

Primary LanguageVisual Basic .NETOtherNOASSERTION

WPF Scheduler - Create Regular and Recurring Appointments at the View Model Level

This example defines View Model commands that add new regular and recurring appointments to the Scheduler Control.

Implementation Details

Note

Your data source type should implement the INotifyCollectionChanged interface (for example, ObservableCollection<T>). In this case, the Scheduler Control receives notifications about its changes.

Create a New Appointment

  1. Create a new data item instance.
  2. Define item properties.
  3. Add this item to your source.

In this example, the SchedulerControl.SelectedInterval property is bound to the Interval View Model property. Its values define Start and End properties of the new data item:

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

Create a New Recurring Appointment

  1. Set the item Type property to Pattern.
  2. Use the RecurrenceBuilder class to generate a recurrence rule.
  3. Assign this rule to the RecurrenceInfo property to create a recurring appointment.
[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);
}

Edit the Created Appointment

This example also illustrates how to invoke the Appointment Window for the newly created appointment:

  1. Attach the CompositeCommandBehavior to the button that should create appointments.
  2. Bind the first CommandItem.Command property to the View Model command that adds appointments.
  3. Bind the second CommandItem.Command property to the Scheduler Control ShowAppointmentWindowCommand.
<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>

Files to Review

Documentation

More Examples