Skip to main content
A newer version of this page is available. .

IAppointmentFactory Interface

Provides methods for creating appointments.

Namespace: DevExpress.XtraScheduler

Assembly: DevExpress.XtraScheduler.v20.2.Core.dll

NuGet Packages: DevExpress.Scheduler.Core, DevExpress.WindowsDesktop.Scheduler.Core

Declaration

public interface IAppointmentFactory

The following members return IAppointmentFactory objects:

Remarks

Warning

Creating custom appointments is not safe and may lead to the control malfunction. It is strongly recommended that you use custom fields and mappings instead.

The IAppointmentFactory interface declares the IAppointmentFactory.CreateAppointment method, which defines a way of creating appointments. To specify a custom way of creating appointments using the SchedulerStorage you should implement this method and then assign the new appointment factory to the Scheduler Storage via the SchedulerStorageBase.SetAppointmentFactory method.

Then the Scheduler Storage will use this factory when creating an appointment via its SchedulerStorageBase.CreateAppointment method.

The following code illustrates the use of the IAppointmentFactory interface to implement a wrapper class which is intended to expose custom fields as common object properties. Using the AppointmentStorageBase.SetAppointmentFactory method, Scheduler’s Appointment objects are replaced with the Task class instances. A TaskCollection class holds Task objects, and can be used as a data source capable of providing data contained within appointment custom fields.

public class TaskFactory : IAppointmentFactory
{
    public Appointment CreateAppointment(AppointmentType type)
    {
        Task task = new Task(type);
        return task;
    }
}
public class Task : DevExpress.XtraScheduler.Internal.Implementations.AppointmentInstance {

    public Task()  { }
    public Task (AppointmentType type) : base(type){}

    // Convert custom fields into the Task properties
    public string CustomText {
        get { return (string)base.CustomFields["CustomTextField"]; }
        set { base.CustomFields["CustomTextField"] = value; }
    }
    public Color CustomColor {
        get { return (Color)base.CustomFields["CustomColorField"]; }
        set { base.CustomFields["CustomColorField"] = value; }
    }
    public int CustomColorARGB { get { return ((Color)base.CustomFields["CustomColorField"]).ToArgb(); } }
}
public class TaskCollection : List<Task> {

    public void AddAppointment(Appointment appointment) {
        Task task = (Task)appointment;
        base.Add(task);
    }

    public virtual void AddAppointmentRange(AppointmentBaseCollection collection) {
        foreach(Appointment item in collection)
            this.AddAppointment(item);
    }
}
See Also