Strip Lines in WPF Gantt

31 Mar 202210 minutes to read

The Gantt provides support to add strip lines in the Gantt chart region that denotes an important event in a sequential timeline. By using this feature, you can add strip lines to highlight the important days in your project. You can add a collection of strip lines using the provided API.

Strip lines in Essential Gantt support the following features:

Strip lines can be repeatable in the Gantt chart region based on repeat behavior and repeat interval.

  • You can modify the content or appearance of the strip lines at run time by changing the values of the underlying collection source.
  • The visibility of strip lines can be toggled using the ShowStripLines property in the Gantt control.

The Gantt control will get the information from the application to draw the strip lines. Gantt will accept the strip line information in the form of a collection of StripLineInfo objects and process it to draw the strip lines.

Repeat behavior

The available repeat behaviors are as follows:

  • Year
  • Month
  • Week
  • Day
  • Hour
  • Minute

Style selector

It used to pass the style of the strip lines dynamically. Based on constraints.

Template selector

It used to pass the content template of the strip lines dynamically based on constraints.

Types of strip lines

There are two types of strip lines available in Essential Gantt. They are:

  • Regular
  • Absolute—Absolute type will place the strip line at any user-defined point.

Properties

Property Description Type Data Type
Background Gets/sets background color of strip line. CLR Brush
Content Gets/sets the content of the strip line. CLR Object
ContentTemplate Gets/sets the content template of the strip line. CLR DataTemplate
ContentTemplateSelector Gets/sets the TemplateSelector of the strip line. CLR DataTemplateSelector
StartDate Gets/sets the start date of the strip line. CLR DateTime
EndDate Gets/sets the end date of the strip line. CLR DateTime
RepeatBehavior Gets/sets the repeat behavior of the strip line. CLR Repeat (Enum)
RepeatFor Gets/sets the intervals between the repeating strip lines. CLR Integer
RepeatUpto Gets/sets DateTime value. The strip line will be repeated up to this value. CLR DateTime
Style Gets/sets the style for the strip line. CLR Style
StyleSelector Gets/sets the style selector of the strip line. CLR StyleSelector
VerticalContentAlignment Gets/sets the vertical alignment of the content present in the strip line. CLR VerticalAlignment
HorizontalContentAlignment Gets/sets the horizontal alignment of the content present in the strip line. CLR Horizontal Alignment
Type Gets/sets the type of the strip line. CLR StriplineType(Enum)
Position Gets/sets the absolute position of the strip line for Absolute strip line type. CLR Point
Height Gets/sets the absolute height of the strip line for Absolute strip line type. CLR Double
Width Get/sets the absolute width of the strip line for Absolute strip line type. CLR Double

Use Case Scenarios

  • You can mark the important dates and meetings in the scheduled time line.
  • Strip lines help you to avoid missing important events.

Properties

Property Description Type Data Type
ShowStripLines Get the user option to show the strip lines. Dependency Property Bool
StripLines Get/sets the collection of StripLineInfo from the user. Dependency Property IEnumerable

Enums

Property Description
Repeat This property contains the following values:Year: Repeating the strip line on a yearly basis depends on the RepeatFor value in StripLineInfo.Month: Repeating the strip line on a monthly basis depends on the RepeatFor value in StripLineInfo.Week: Repeating the strip line on a weekly basis depends on the RepeatFor value in StripLineInfo.Day: Repeating the strip line on a daily basis depends on the RepeatFor value in StripLineInfo.Hour: Repeating the strip line on an hourly basis depends on the RepeatFor value in StripLineInfo.Minute: Repeating the strip line on per-minute basis depends on the RepeatFor value in StripLineInfo.
StriplineType This property contains the following values:Regular: This denotes the normal strip line.Absolute: This denotes the absolute strip line. You can customize the position, size, and appearance of the strip line in this type.

Events

By handling its event, you can customize the strip lines dynamically.

Event Description Arguments Type
StripLineCreated Whenever a strip line is created, this event will be triggered. the handler of the event will have the newly created strip line (StripLineInfo) in the argument.By handling this event, you can customize the appearance of the strip line. StripLineCreated(object sender, StriplineCreatedEventArgs args) Event

Adding strip lines to application

Regular strip lines

The following code sample demonstrates how to define a collection of regular strip lines.

  • c#
  • StripCollection =  new List<StripLineInfo>();
    
    //Getting the collection of StripLineInfo
    StripCollection = GetStripCollection();
    
    //Method will return the collection StripLineInfo
    private List<StripLineInfo> GetStripCollection()
    
    {
        List<StripLineInfo> stripCollection = new List<StripLineInfo>();
        stripCollection.Add(new StripLineInfo() 
        { 
            Content =  "Weekly Team Meeting", 
            StartDate = new DateTime(2012, 6, 4), 
            EndDate = new DateTime(2012, 6, 4), 
            HorizontalContentAlignment = HorizontalAlignment.Center, 
            VerticalContentAlignment = VerticalAlignment.Center, 
            Background =  Brushes.Gold, RepeatBehavior = Repeat.Week, RepeatFor = 1,
            RepeatUpto = new DateTime(2012, 12, 10),
        });
    
        return stripCollection;
    }

    The following code sample demonstrates how to bind the regular strip line collection to strip lines.

  • xaml
  • <sync:GanttControl x:Name="Gantt"
                       Grid.Row="1"
                       ShowStripLines="True"
                       StripLines="{Binding StripCollection}">
        <sync:GanttControl.TaskAttributeMapping>
            <sync:TaskAttributeMapping TaskIdMapping="TaskId"
                                       TaskNameMapping="TaskName"
                                       StartDateMapping="StartDate"
                                       FinishDateMapping="FinishDate"
                                       ChildMapping="Child"
                                       DurationMapping="Duration"
                                       ProgressMapping="Progress"
                                       PredecessorMapping="Predecessor"
                                       ResourceInfoMapping="Resources"/>
        </sync:GanttControl.TaskAttributeMapping>
    </sync:GanttControl>

    Output

    The following screenshot illustrates how to render the regular strip lines.

    WPF Gantt with regular strip line

    Strip lines in the Gantt chart

    Absolute Strip lines

    The following code sample demonstrates how to define a collection of absolute strip lines.

  • c#
  • StripCollection =  new List<StripLineInfo>();
    
    //Getting the collection of StripLineInfo
    StripCollection = GetStripCollection();
    
    //Method will return the collection StripLineInfo
    private List<StripLineInfo> GetStripCollection()
    
    {
        List<StripLineInfo> stripCollection = new List<StripLineInfo>();
        stripCollection.Add(new StripLineInfo()
        {
            Type = StriplineType.Absolute,
            Height = 1500,
            Width = 200,
            Position = new System.Windows.Point(300, 5),
            Background = new SolidColorBrush(Colors.LightGray)
        });
        return stripCollection;
    }

    The following code sample demonstrates how to bind the absolute strip line collection to strip lines.

  • xaml
  • <sync:GanttControl x:Name="Gantt"
                       Grid.Row="1"
                       ShowStripLines="True"
                       StripLines="{Binding StripCollection}">
        <sync:GanttControl.TaskAttributeMapping>
            <sync:TaskAttributeMapping TaskIdMapping="TaskId"
                                       TaskNameMapping="TaskName"
                                       StartDateMapping="StartDate"
                                       FinishDateMapping="FinishDate"
                                       ChildMapping="Child"
                                       DurationMapping="Duration"
                                       ProgressMapping="Progress"
                                       PredecessorMapping="Predecessor"
                                       ResourceInfoMapping="Resources"/>
        </sync:GanttControl.TaskAttributeMapping>
    </sync:GanttControl>

    Output

    The following screenshot illustrates how to render the absolute strip lines.

    WPF Gantt with absolute strip line

    Strip lines in the Gantt chart

    To view samples:

    1. Go to the Syncfusion Essential Studio installed location.
      Location: Installed Location\Syncfusion\Essential Studio\19.3.0.43\Infrastructure\Launcher\Syncfusion Control Panel
    2. Open the Syncfusion Control Panel in the above location (or) Double click on the Syncfusion Control Panel desktop shortcut menu.
    3. Click Run Samples for WPF under the User Interface Edition panel.
    4. Select Gantt.
    5. Expand the Interactive Features item in the Sample Browser.
    6. Choose the Strip Lines sample to launch.

    see also

    How to enable horizontal lines for gantt chart rows