Skip to main content
A newer version of this page is available. .

How to: Set the Color of the RangeControl Thumbnails (legacy)

  • 2 minutes to read

Note

You are viewing documentation for the legacy WPF Scheduler control. If you’re starting a new project, we strongly recommend that you use a new control declared in the DevExpress.Xpf.Scheduling namespace. If you decide to upgrade an existing project in order to switch to the updated scheduler control, see the Migration Guidelines document.

This example demonstrates how you can specify the color of the Range Control thumbnails in code.

The background color of the thumbnail is determined by the ThumbnailControl template. The Border.Background property of the thumbnail is bound to the appointment it represents and uses a custom AppointmentToColorConverter. The converter specifies the color according to words encountered in the Appointment.Location string.

RangeControl-Thumbnails-TimelineView

public class AppointmentToColorConverter : MarkupExtension, IValueConverter
{
    AppointmentToColorConverter instance = null;

    public AppointmentToColorConverter(){}

    public Color DefaultColor { get; set; }

    public override object ProvideValue(IServiceProvider serviceProvider)
    {
        if (instance == null)
        {
            instance = new AppointmentToColorConverter();
            instance.DefaultColor = DefaultColor;
        }
        return instance;
    }
    object IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        Appointment apt = value as Appointment;
        if (apt.Location == String.Empty)
            return Brushes.White;
        if (apt.Location.Contains("Orange"))
            return Brushes.Orange;
        if (apt.Location.Contains("Green"))
            return Brushes.Green;
        if (apt.Location.Contains("Blue"))
            return Brushes.Blue;
        return Brushes.Gray;
    }
    object IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return ((SolidColorBrush)value).Color;
    }
}