Change label color by script

Contents[Hide]

1. Overview

This article shows you how to change a label or another component's background color using script. For example, you may want to change the color of the background of a component when it is clicked or hovered over.

2. Setting up

In this example, we have a label component.

Sample label
Sample label

It has the following Look properties, with a background color of #F2F2F2.

Initial label properties
Initial label properties

3. Adding the script

If you want to change the label when an action is performed, add the following script to a list in the Properties window's Actions section, such as Click:

label1.background = new dundas.controls.SolidColorBrush(new dundas.controls.Color(0xFFAAAA));

Script editor
Script editor

This uses the following API properties and classes:

Once this is added, you can choose Sandbox View in the toolbar to test the script.

Label after click
Label after click

4. See also

Dundas Data Visualization, Inc.
500-250 Ferrand Drive
Toronto, ON, Canada
M3C 3G8

North America: 1.800.463.1492
International: 1.416.467.5100

Dundas Support Hours: 7am-6pm, ET, Mon-Fri