Change Gantt Task color as per status

2 posts, 0 answers
  1. Prolay
    Prolay avatar
    27 posts
    Member since:
    Nov 2012

    Posted 03 Dec 2012 Link to this post

    Hi,

    For a project level gantt chart i need to change the color of gantt task as per the project status. The possible project status can be more than two like Open, OnHold, Complete. Is there a way to change color based on condition.



    Regards,
    Prolay
  2. Miroslav Nedyalkov
    Admin
    Miroslav Nedyalkov avatar
    1718 posts

    Posted 05 Dec 2012 Link to this post

    Hi Prolay,

    The easiest way of doing this is to bind the Background property of the EventContainer control to the property of the GanttTask holding this information using a ValueConverter. Here is an example how to do this if you have a property called Background of type Brush in your custom GanttTask:
    <telerik:RadGanttView VisibleRange="{Binding VisibleRange}" TasksSource="{Binding Tasks}">
        <telerik:RadGanttView.Resources>
            <Style TargetType="telerik:EventContainer">
                <Setter Property="Background" Value="{Binding OriginalEvent.Background}" />
            </Style>
        </telerik:RadGanttView.Resources>
    </telerik:RadGanttView>

    Here is the code of the custom GanttTask:
    public class CustomTask : GanttTask
    {
        private Brush background;
     
        /// <Summary>Gets or sets Background and notifies for changes</Summary>
        public Brush Background
        {
            get { return this.background; }
            set
            {
                if (this.background != value)
                {
                    this.background = value;
                    this.OnPropertyChanged(() => this.Background);
                }
            }
        }
    }

    Hope this helps.

    Regards,
    Miroslav Nedyalkov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. DevCraft banner
Back to Top