Back to Devexpress

How to: Set Default Values for a New Appointment

wpf-119238-controls-and-libraries-scheduler-examples-how-to-set-default-values-for-a-new-appointment.md

latest3.4 KB
Original Source

How to: Set Default Values for a New Appointment

  • Apr 09, 2021
  • 2 minutes to read

The SchedulerControl provides an SchedulerControl.InitNewAppointment event that allows you to change a newly created appointment’s default characteristics.

Specifically, you can delete a reminder which is automatically assigned to a new appointment.

This example uses the EventToCommand behavior implemented in DevExpress MVVM Framework to bind the SchedulerControl’s event to a command in a view model.

The following code implements a special EventToCommand behavior that allows you to bind an SchedulerControl.InitNewAppointment event to a Delegate Command. The delegate command is generated automatically from a public InitNewAppointment method declared in a POCO View Model view model. Instead of passing event arguments to a method in a view model, the code specifies the NewAppointmentInitConverter converter that processes event arguments.

View Example

xaml
<dxmvvm:Interaction.Behaviors>
    <dxmvvm:EventToCommand EventName="InitNewAppointment" Command="{Binding InitNewAppointmentCommand}">
        <dxmvvm:EventToCommand.EventArgsConverter>
            <local:NewAppointmentInitConverter/>
        </dxmvvm:EventToCommand.EventArgsConverter>
    </dxmvvm:EventToCommand>
</dxmvvm:Interaction.Behaviors>

The NewAppointmentInitConverter converter changes the appointment’s label and removes the default reminder.

View Example

csharp
using DevExpress.Mvvm.UI;
using DevExpress.Xpf.Scheduling;

namespace CustomMvvmFormWithRecurrenceExample {
    public class NewAppointmentInitConverter : EventArgsConverterBase<AppointmentItemEventArgs> {
        protected override object Convert(object sender, AppointmentItemEventArgs args) {
            args.Appointment.LabelId = 1;
            args.Appointment.Reminders.Clear();
            return args;
        }
    }
}
vb
Imports DevExpress.Mvvm.UI
Imports DevExpress.Xpf.Scheduling

Namespace CustomMvvmFormWithRecurrenceExample
    Public Class NewAppointmentInitConverter
        Inherits EventArgsConverterBase(Of AppointmentItemEventArgs)

        Protected Overrides Function Convert(ByVal sender As Object, ByVal args As AppointmentItemEventArgs) As Object
            args.Appointment.LabelId = 1
            args.Appointment.Reminders.Clear()
            Return args
        End Function
    End Class
End Namespace