How to color the tasks with dependencies differently?
Sometimes you might want to color tasks with dependencies (either successor or predecessor) differently like this:
Custom colors for dependent lines
You can do so as follows:
Step 1: First listen to these events that cause some tasks to participate in dependencies:
void ganttControl_DependencyLineAdded(object sender, DependencyLineEventArgs e)
{
this.ResetTaskColors();
}
This event will fire when you draw the dependency line between tasks.
void ganttControl_DependencyLineRemoved(object sender, DependencyLineEventArgs e)
{
this.ResetTaskColors();
}
private void ResetTaskColors()
{
this.ganttControl.TaskColorsBinding = new Binding("DataSource")
{
Converter = new CustomTaskColorProvider() { DepCollections =
//Contains the gantt dependencylines
this.ganttControl.Model.Dependencies }
};
}
Step 2: Implement this converter used above that will render these tasks that participate in dependencies differently:
public class CustomTaskColorProvider : IValueConverter
{
public DependenciesCollection DepCollections{get;set;}
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
IActivity activity = parameter as IActivity;
// If this activity participates in dependency
if (this.IsTaskDepended(activity))
{
LinearGradientBrush barStrokeBrush = new LinearGradientBrush() { StartPoint = new Point(0, 0), EndPoint = new Point(0, 1) };
barStrokeBrush.GradientStops.Add(new GradientStop() { Color = Colors.Transparent, Offset = 0 });
barStrokeBrush.GradientStops.Add(new GradientStop() { Color = Color.FromArgb(255, 0xFF, 0xA0, 0x7A), Offset = 0.25 });
barStrokeBrush.GradientStops.Add(new GradientStop() { Color = Color.FromArgb(255, 0xFF, 0x63, 0x47), Offset = 1 });
return new TaskSpecificLook()
{
TaskItemBarFill = barStrokeBrush,
TaskItemBarStroke = new SolidColorBrush(Color.FromArgb(255, 0xFF, 0x63, 0x47)),
TaskItemProgressFill = new SolidColorBrush(Colors.Black),
SummaryItemBarStroke = new SolidColorBrush(Color.FromArgb(255, 0xFF, 0x63, 0x47)),
};
}
return null;
}
public bool IsTaskDepended(IActivity activity)
{
// returns true if this activity participates in dependency
return DepCollections[activity]!=null;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
� RadiantQ 2009 - 2019. All Rights Reserved.