Back to Devexpress

SchedulerControl.CustomWorkTime Event

wpf-devexpress-dot-xpf-dot-scheduling-dot-schedulercontrol-3681855e.md

latest8.7 KB
Original Source

SchedulerControl.CustomWorkTime Event

Allows you to specify several custom work time intervals per day, which can be set differently for distinct days and resources.

Namespace : DevExpress.Xpf.Scheduling

Assembly : DevExpress.Xpf.Scheduling.v25.2.dll

NuGet Package : DevExpress.Wpf.Scheduling

Declaration

csharp
public event CustomWorkTimeEventHandler CustomWorkTime
vb
Public Event CustomWorkTime As CustomWorkTimeEventHandler

Event Data

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

PropertyDescription
IntervalGets the time interval for which a work time setting is obtained.
ResourceGets the resource for which a work time setting is obtained.
WorkTimeGets or sets a single work time interval.
WorkTimesGets or sets a collection of work time intervals.

Remarks

Handle the CustomWorkTime event and use the CustomWorkTimeEventArgs.Interval and CustomWorkTimeEventArgs.Resource properties to determine the range for which time intervals are specified. Set a single work time interval with the CustomWorkTimeEventArgs.WorkTime property. Use the CustomWorkTimeEventArgs.WorkTimes property to specify several work time intervals.

Example

This example demonstrates how to use the SchedulerControl.CustomWorkTime event to specify several work time intervals per day, which vary for different days and resources.

View Example

xaml
<dxsch:SchedulerControl CustomWorkTime="SchedulerControl_CustomWorkTime"
    GroupType="Resource"
    ResourceBrushSchemas="{StaticResource MyResourceSchemas}">
    <dxsch:SchedulerControl.ResourceItems>
        <dxsch:ResourceItem Caption="One" Id="1" />
        <dxsch:ResourceItem Caption="Two" Id="2" />
        <dxsch:ResourceItem Caption="Three" Id="3" />
        <dxsch:ResourceItem Caption="Four" Id="4" />
    </dxsch:SchedulerControl.ResourceItems>
    <dxsch:WeekView x:Name="weekView1"
        ResourcesPerPage="4"
        ShowAllDayArea="False"
        NavigationButtonsVisibility="Never"
        DateHeaderContentTemplate="{StaticResource DateHeaderControl.ContentTemplate}"/>
    <dxsch:TimelineView x:Name="timelineView1"/>
</dxsch:SchedulerControl>
csharp
private void SchedulerControl_CustomWorkTime(object sender, DevExpress.Xpf.Scheduling.CustomWorkTimeEventArgs e)
{
    if (e.Resource.Id.Equals("1"))
    {
        if (e.Interval.Start.Day % 2 == 0)
        {
            List<TimeSpanRange> workTimes = new List<TimeSpanRange>();
            workTimes.Add(new TimeSpanRange(TimeSpan.FromHours(0), TimeSpan.FromHours(3)));
            workTimes.Add(new TimeSpanRange(TimeSpan.FromHours(5), TimeSpan.FromHours(8)));
            workTimes.Add(new TimeSpanRange(TimeSpan.FromHours(10), TimeSpan.FromHours(11)));
            e.WorkTimes = workTimes;
        }
        else
            e.WorkTime = new TimeSpanRange(TimeSpan.FromHours(8), TimeSpan.FromHours(20));
    }
    if (e.Resource.Id.Equals("2"))
    {
        if (e.Interval.Start.Day % 2 == 0)
            e.WorkTime = new TimeSpanRange(TimeSpan.FromHours(14), TimeSpan.FromHours(18));
        else
            e.WorkTime = new TimeSpanRange(TimeSpan.FromHours(8), TimeSpan.FromHours(12));
    }
    if (e.Resource.Id.Equals("3"))
        e.WorkTime = new TimeSpanRange(TimeSpan.FromHours(14), TimeSpan.FromHours(21));
    if (e.Resource.Id.Equals("4"))
    {
        List<TimeSpanRange> workTimes = new List<TimeSpanRange>();
        workTimes.Add(new TimeSpanRange(TimeSpan.FromHours(8), TimeSpan.FromHours(11)));
        workTimes.Add(new TimeSpanRange(TimeSpan.FromHours(13), TimeSpan.FromHours(17)));
        e.WorkTimes = workTimes;
    }
}
vb
Private Sub SchedulerControl_CustomWorkTime(ByVal sender As Object, ByVal e As DevExpress.Xpf.Scheduling.CustomWorkTimeEventArgs)
    If e.Resource.Id.Equals("1") Then
        If e.Interval.Start.Day Mod 2 = 0 Then
            Dim workTimes As New List(Of TimeSpanRange)()
            workTimes.Add(New TimeSpanRange(TimeSpan.FromHours(0), TimeSpan.FromHours(3)))
            workTimes.Add(New TimeSpanRange(TimeSpan.FromHours(5), TimeSpan.FromHours(8)))
            workTimes.Add(New TimeSpanRange(TimeSpan.FromHours(10), TimeSpan.FromHours(11)))
            e.WorkTimes = workTimes
        Else
            e.WorkTime = New TimeSpanRange(TimeSpan.FromHours(8), TimeSpan.FromHours(20))
        End If
    End If
    If e.Resource.Id.Equals("2") Then
        If e.Interval.Start.Day Mod 2 = 0 Then
            e.WorkTime = New TimeSpanRange(TimeSpan.FromHours(14), TimeSpan.FromHours(18))
        Else
            e.WorkTime = New TimeSpanRange(TimeSpan.FromHours(8), TimeSpan.FromHours(12))
        End If
    End If
    If e.Resource.Id.Equals("3") Then
        e.WorkTime = New TimeSpanRange(TimeSpan.FromHours(14), TimeSpan.FromHours(21))
    End If
    If e.Resource.Id.Equals("4") Then
        Dim workTimes As New List(Of TimeSpanRange)()
        workTimes.Add(New TimeSpanRange(TimeSpan.FromHours(8), TimeSpan.FromHours(11)))
        workTimes.Add(New TimeSpanRange(TimeSpan.FromHours(13), TimeSpan.FromHours(17)))
        e.WorkTimes = workTimes
    End If
End Sub

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the CustomWorkTime event.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

wpf-scheduler-specify-custom-work-time-intervals/CS/CustomWorkTimeExample/MainWindow.xaml#L29

xml
<Grid>
    <dxsch:SchedulerControl CustomWorkTime="SchedulerControl_CustomWorkTime"
                            GroupType="Resource"

wpf-scheduler-specify-custom-work-time-intervals/CS/CustomWorkTimeExample/obj/Debug/net8.0-windows/MainWindow.g.cs#L97

csharp
#line 29 "..\..\..\MainWindow.xaml"
((DevExpress.Xpf.Scheduling.SchedulerControl)(target)).CustomWorkTime += new DevExpress.Xpf.Scheduling.CustomWorkTimeEventHandler(this.SchedulerControl_CustomWorkTime);

wpf-scheduler-specify-custom-work-time-intervals/VB/CustomWorkTimeExample/obj.NetFX/Debug/MainWindow.g.vb#L95

vb
#ExternalSource("..\..\MainWindow.xaml",29)
AddHandler CType(target,DevExpress.Xpf.Scheduling.SchedulerControl).CustomWorkTime, New DevExpress.Xpf.Scheduling.CustomWorkTimeEventHandler(AddressOf Me.SchedulerControl_CustomWorkTime)

See Also

SchedulerControl Class

SchedulerControl Members

DevExpress.Xpf.Scheduling Namespace