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

SchedulerControl.QueryResourceColorSchema Event

Enables visible resources to be painted according to certain conditions.

Namespace: DevExpress.Xpf.Scheduler

Assembly: DevExpress.Xpf.Scheduler.v19.2.dll

Declaration

public event QueryResourceColorSchemaEventHandler QueryResourceColorSchema

Event Data

The QueryResourceColorSchema event's data class is QueryResourceColorSchemaEventArgs. The following properties provide information specific to this event:

Property Description
Resource Gets the resource for which the color schema is queried.
ResourceColorIndex Gets the index of the processed resource’s color schema in a SchedulerColorSchemaCollection collection.
ResourceColorSchema Gets or sets a color schema to be used for a visible resource coloring.

Remarks

Important

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.

By default, if you change a set of visible resources (for example, by using resource filter controls) the collection of resource color schemas will remain unchanged (SchedulerControl.GetResourceColorSchemasCopy), i.e. the same color schemas in the same order will be used to paint resources newly selected for display in the scheduler.

DXScheduler_DefaultResourceColorSchemas

However, you can assign a specific color schema to each resource to be displayed. To do this, handle the QueryResourceColorSchema event.

DXScheduler_QueryResourceColorSchema

The QueryResourceColorSchema event is raised before a resource to be displayed in the scheduler is painted. The event parameter’s QueryResourceColorSchemaEventArgs.Resource property provides information on a processed resource. To associate this resource with a required color schema, use the QueryResourceColorSchemaEventArgs.ResourceColorSchema property.

The QueryResourceColorSchema event can be helpful, if it is required to paint resources according to certain conditions (for example, to highlight a selected resource or specify a certain color schema for a resource, depending on its custom field value, etc.).

Example

This example demonstrates how to link a specific SchedulerColorSchema to each visible resource.

Call the SchedulerControl.GetResourceColorSchemasCopy method to obtain a collection of color schemas that are currently available for resource coloring and handle the SchedulerControl.QueryResourceColorSchema event to associate a specific color schema from the obtained collection to each resource displayed in the scheduler control.

Tip

A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=E3208.

using DevExpress.XtraScheduler;
using System.Collections.Generic;
// ...

namespace WpfApplication1 {
    public partial class MainWindow : Window {

        Dictionary<object, SchedulerColorSchema> resourceColorSchemas = 
            new Dictionary<object, SchedulerColorSchema>();

        public MainWindow() {
            InitializeComponent();

            // Get copies of color schemas that are currently used to paint resources.
            PrepareResourceColorSchemas();
        }

        // ...

        private void PrepareResourceColorSchemas() {
            int count = schedulerControl1.Storage.ResourceStorage.Count;
            SchedulerColorSchemaCollection currentColorchemas = 
                schedulerControl1.GetResourceColorSchemasCopy();
            int schemaCount = currentColorchemas.Count;
            for (int i = 0; i < count; i++) {
                Resource resource = schedulerControl1.Storage.ResourceStorage[i];
                resourceColorSchemas.Add(resource.Id, currentColorchemas[i % schemaCount]);
            }
        }

        private void schedulerControl1_QueryResourceColorSchema(object sender, 
                                                                QueryResourceColorSchemaEventArgs e) {
            object key = e.Resource.Id;
            if (this.resourceColorSchemas.ContainsKey(key))
                e.ResourceColorSchema = this.resourceColorSchemas[key];
            }
        }
    }
}

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the QueryResourceColorSchema event.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also