Skip to main content

SchedulerControl.QueryWorkTime Event

Occurs when the Scheduler control’s view calculates the work time interval for the specific resource.

Namespace: DevExpress.Xpf.Scheduler

Assembly: DevExpress.Xpf.Scheduler.v24.1.dll

NuGet Package: DevExpress.Wpf.Scheduler

Declaration

public event QueryWorkTimeEventHandler QueryWorkTime

Event Data

The QueryWorkTime event's data class is QueryWorkTimeEventArgs. The following properties provide information specific to this event:

Property Description
Interval Gets the time interval for which the working time is queried.
Resource Gets the resource for which the working time interval is queried.
WorkTime Gets or sets the working time interval.
WorkTimes Provides access to the collection of work times specified for a single day.

Remarks

Important

You are viewing documentation for the legacy WPF Scheduler control. If you’re starting a new project, we strongly recommend that you use a new control declared in the DevExpress.Xpf.Scheduling namespace. If you decide to upgrade an existing project in order to switch to the updated scheduler control, see the Migration Guidelines document.

Handle the QueryWorkTime event to specify custom work time intervals. They can be set differently for distinct days and resources.

Note

When different work time intervals are specified in the SchedulerControl.QueryWorkTime event handler, the DayView.ShowWorkTimeOnly option has no effect.

Example

This example demonstrates how to set a custom work time for each day and resource.

To do this, handle the SchedulerControl.QueryWorkTime event, check values of the QueryWorkTimeEventArgs.Interval and QueryWorkTimeEventArgs.Resource properties and set the QueryWorkTimeEventArgs.WorkTime property value, as required.

using DevExpress.XtraScheduler;
using DevExpress.Xpf.Scheduler;
//...

// Create a collection of different worktime intervals.
TimeOfDayInterval[] workTimes = new TimeOfDayInterval[] {
    new TimeOfDayInterval(TimeSpan.FromHours(0), TimeSpan.FromHours(16)),
    new TimeOfDayInterval(TimeSpan.FromHours(10), TimeSpan.FromHours(20)),
    null,
    new TimeOfDayInterval(TimeSpan.FromHours(7), TimeSpan.FromHours(15)),
    new TimeOfDayInterval(TimeSpan.FromHours(16), TimeSpan.FromHours(24)),
        };

private void schedulerControl1_QueryWorkTime(object sender, QueryWorkTimeEventArgs e) {

    if(schedulerControl1.Storage.ResourceStorage == null)
        return;

    int resourceIndex = schedulerControl1.Storage.ResourceStorage.Items.IndexOf(e.Resource);
    if(resourceIndex >= 0) {
        if(resourceIndex == 0) {
        // Specify alternate worktimes for odd and even days.
            if((e.Interval.Start.Day % 2) == 0)
                e.WorkTime = workTimes[resourceIndex % workTimes.Length];
            else
                e.WorkTime = TimeOfDayInterval.Empty;
        }
        else {
            // Specify worktime interval if the current date is treated as a working day.
            if (schedulerControl1.WorkDays.IsWorkDay(e.Interval.Start.Date))
                e.WorkTime = workTimes[resourceIndex % workTimes.Length];
        }
    }
}
See Also