SchedulerPrintAdapter.GetService(Type) Method

Gets the service object of the specified type.

Namespace: DevExpress.XtraScheduler.Reporting

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

Declaration

public object GetService(
    Type serviceType
)
Public Function GetService(
    serviceType As Type
) As Object

Parameters

Name Type Description
serviceType Type

An object that specifies the type of service object to get.

Returns

Type Description
Object

A service object of the specified type, or a null reference (Nothing in Visual Basic) if there is no service object of this type.

Remarks

Use this method to enable your application objects to obtain a service of the SchedulerControl in order to employ its methods. The scheduler implements the IServiceProvider interface, so you can tell it what type of service you wish to retrive via the GetService method; and if a service is available, it is offered to the caller object.

NOTE

Currently only the SchedulerStoragePrintAdapter supports services. You should check the type of the print adapter and cast it to the SchedulerStoragePrintAdapter type.

The following code snippet illustrates how the HeaderCaptionService is substituted to modify the date format of the header caption. Other services can be used similarly.

using DevExpress.XtraScheduler.Reporting;
using DevExpress.XtraScheduler.Services;
using DevExpress.XtraScheduler.Drawing;
using DevExpress.XtraScheduler.Services.Implementation;
// ...
    string dateFormat = "dd-MMM, ddd";
    SchedulerStoragePrintAdapter storagePrintAdapter = 
        XtraSchedulerReport1.SchedulerAdapter as SchedulerStoragePrintAdapter;
    if (storagePrintAdapter != null) {
        storagePrintAdapter.RemoveService(typeof(IHeaderCaptionService));
        IHeaderCaptionService customHeaderCaptionService = 
            new CustomHeaderCaptionService(dateFormat);
        storagePrintAdapter.AddService(typeof(IHeaderCaptionService), 
            customHeaderCaptionService);
    }

public class CustomHeaderCaptionService : HeaderCaptionServiceWrapper {
    string format;
    public CustomHeaderCaptionService(string format)
        : base(new HeaderCaptionService()) {
        this.format = format;
    }
    protected virtual string CreateFormat(string format) {
        if(format == "Default")
            return string.Empty;
        return String.Format("{{0:{0}}}", format);
    }
    public override string GetDayColumnHeaderCaption(DayHeader header) {
        return CreateFormat(format);
    }
}

Implements

See Also