Skip to main content

Working and Non-Working Time Ranges

  • 3 minutes to read

The GanttControl allows you to specify the following working and non-working time ranges:

  • working and non-working time (for example, breaks)

  • working and non-working days (for example, holidays, weekends)

This topic describes how to define working and non-working time ranges, and change their visibility and appearance.

Non-Working Time Range Visibility

The GanttControl provides the following properties that allow you to change the visibility of non-working time ranges in the Gantt area:

These properties return the following TimeIntervalDisplayMode enumeration values:

Property Description
TimeIntervalDisplayMode.Cut

The time intervals are cut out from the timeline.

TimeIntervalDisplayMode.Hide

The time intervals are not visually highlighted in the timeline.

TimeIntervalDisplayMode.Show

The time intervals are displayed and highlighted in the timeline.

Working and Non-Working Time Rules

The GanttControl stores its working time rules within the GanttView.WorkingTimeRules collection. This collection provides methods that allow you to add new and remove existing rules. Individual rules are represented by WorkingTimeRule objects.

Working time rules contain the following information:

The code sample below demonstrates how to define working time rules.

<dxgn:GanttControl ItemsSource="{Binding Tasks}">
    <dxgn:GanttControl.View>
        <dxgn:GanttView ...
            NonworkingTimeDisplayMode="Show"> 
            <dxgn:GanttView.WorkingTimeRules> 
                <dxgn:WorkingTimeRule Recurrence="{dxgn:Daily}" WorkingTime="9:0:0-13:0:0, 14:0:0-18:0:0" /> 
                <dxgn:WorkingTimeRule Recurrence="{dxgn:Weekly DayOfWeek=Thursday}" WorkingTime="9:0:0-13:0:0, 14:0:0-17:0:0" /> 
            </dxgn:GanttView.WorkingTimeRules> 
        </dxgn:GanttView> 
    </dxgn:GanttControl.View> 
</dxgn:GanttControl>

Working and Non-Working Day Rules

The GanttControl stores its workday rules within the WorkdayRules collection. This collection provides methods that allow you to add new and remove existing rules. Individual rules are represented by WorkdayRule objects.

Workday rules contain the following information:

The code sample below demonstrates how to define the working and non-working day rules.

<dxgn:GanttControl ItemsSource="{Binding Tasks}">
    <dxgn:GanttControl.View>
        <dxgn:GanttView
            NonworkingDayDisplayMode="Show">
            <dxgn:GanttView.WorkdayRules>
                <dxgn:WorkdayRule IsWorkday="False" Recurrence="{dxgn:Yearly Day=1, Month=1}" />
                <dxgn:WorkdayRule IsWorkday="True" Recurrence="{dxgn:Weekly DayOfWeek=Saturday, Interval=2}" />
            </dxgn:GanttView.WorkdayRules>
        </dxgn:GanttView>
    </dxgn:GanttControl.View>
</dxgn:GanttControl> 

Rule Recurrence

Working time and workday rules can reoccur multiple times. The GanttControl allows you to configure rule recurrence:

  • Daily

    <!-- The rule's recurrence is set to Daily -->
    <dxgn:WorkingTimeRule Recurrence="{dxgn:Daily}" WorkingTime="9:0:0-13:0:0, 14:0:0-18:0:0" />
    
  • Weekly

    <!-- Applies to every Friday from January, 1, 2019 to July, 1, 2019 -->
    <dxgn:WorkdayRule IsWorkday="False" Recurrence="{dxgn:Weekly DayOfWeek=Friday, Start=1/1/2019, Until=7/1/2019}" />
    <!-- Applies to every second Saturday -->
    <dxgn:WorkdayRule IsWorkday="False" Recurrence="{dxgn:Weekly DayOfWeek=Saturday, Interval=2}" />
    
  • Monthly

    <!-- The rule applies to the first day of each month (January, 1; February, 1; etc.) -->
    <dxgn:WorkingTimeRule Recurrence="{dxgn:Monthly Day=1}" WorkingTime="9:0:0-13:0:0, 14:0:0-17:0:0" />
    
  • MonthlyByDayOfWeek

    <!-- The rule applies to the second week's monday of each month -->
    <dxgn:WorkingTimeRule 
        Recurrence="{dxgn:MonthlyByDayOfWeek DayOfWeek=Monday, Week=2}" 
        WorkingTime="9:0:0-13:0:0, 14:0:0-17:0:0" />
    
  • Yearly

    <!-- Marks January 1 a nonworking day -->
    <dxgn:WorkdayRule IsWorkday="False" Recurrence="{dxgn:Yearly Day=1, Month=1}" />
    
  • YearlyByDayOfYear

    <!-- Marks the last day in the year as a non-working day -->
    <dxgn:WorkdayRule IsWorkday="False" Recurrence="{dxgn:YearlyByDayOfYear DayOfYear=365}" />
    
  • YearlyByDayOfWeek

    <!-- Marks Thanksgiving Day (United States) as a non-working day -->
    <dxgn:WorkdayRule IsWorkday="False" Recurrence="{dxgn:YearlyByDayOfWeek Month=11, DayOfWeek=Thursday, Week=4}" />
    

Appearance Customization

You can control the appearance of non-working time intervals displayed within the Gantt area.

Apply a style to the MarkedTimeControl to change the appearance of the highlighted non-working intervals.

The code sample below demonstrates how to change the color of non-working time intervals within the Gantt area.

<dxgn:GanttControl ItemsSource="{Binding Tasks}">
    <dxgn:GanttControl.Resources>
        <Style TargetType="{x:Type dxgn:MarkedTimeControl}">
            <Setter Property="Background" Value="LightGray"/>
        </Style>
    </dxgn:GanttControl.Resources>
    ...
</dxgn:GanttControl> 

The image below illustrates the result: