Sometimes you have to customize the look and feel of individual task bars based on some value in the bound object or the IActivity instance representing each task.
TaskColorsBinding
This property in GanttControl lets you customize the colors of individual task bars.
To customize the colors based on a property in the corresponding IActivity object, setup the property like this:
// ProgressPercent is a property in IActivity.
this.ganttControl.TaskColorsBinding = new Binding("ProgressPercent")
{
Converter = new CustomColorProvider() { PreferredProgress=25}
};
To customize the colors based on a property in the corresponding bound object, setup the property like this:
// Progress is a property in your bound object. "DataSource" is a property in the IActivity instance representing your bound object
this.ganttControl.TaskColorsBinding = new Binding("DataSource.Progress")
{
Converter = new CustomColorProvider() { PreferredProgress=25}
};
Note: Binding has to be setup in code-behind for this property.
In both the above cases, the Converter would look like this:
public class CustomColorProvider : IValueConverter
{
public double PreferredProgress{get; set;}
public CustomColorProvider()
{
this.PreferredProgress = 25;
}
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
// The parameter will always contain the IActivity for this binding.
IActivity activity = parameter as IActivity;
// If you need the underlying bound object:
TaskInfo ti = ((DataBoundActivity)activity).DataSource as TaskInfo;
// If this is not a summary activity and progress is < the specified threshold render it in a different color
if (activity.ChildActivities.Count == 0 && ti.ProgressPercent < this.PreferredProgress)
{
// Use a reddish brush. Some of these property values in TaskSpecificColors can be null.
return new TaskSpecificColors() { TaskItemBarFill = new SolidColorBrush(Colors.Red), TaskItemBarStroke = new SolidColorBrush(Color.FromArgb(255, 0xFF, 0x63, 0x47)), TaskItemProgressFill = new SolidColorBrush(Colors.Black) };
}
else
return null;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
#endregion
}
With the above setting, the task bars with progress < 25% will be rendered reddish as shown.
Take a look at our GanttControlCustomAppearance sample where this is clearly illustrated.
� RadiantQ 2009 - 2019. All Rights Reserved.