Setting Text Color Dynamically
You can set a font color for text contents dynamically using textColor
tags. Syntax of a textColor
tag is defined as follows.
<<textColor [color_expression]>>
content_to_be_colored
<</textColor>>
Note – A textColor
tag can be used anywhere in a template document except charts.
An expression declared within an opening textColor
tag defines a text font color to be applied during runtime. The expression must return a value of one of the following types:
- A string containing the name of a known color, that is, the case-insensitive name of a member of the KnownColor enumeration like in the following example.
<<textColor [“red”]>>text with red font<</textColor>>
- A string containing an HTML color code like in the following example.
<<textColor [“#F08080”]>>text with light coral font<</textColor>>
- An integer value defining RGB (red, green, blue) components of the color like in the following example.
<<textColor [0xFFFF00]>>text with yellow font<</textColor>>
- A value of the Color type.
While building a report, an expression declared within an opening textColor
tag is evaluated and text content between the tag and its corresponding closing tag is colored accordingly. The opening and closing textColor
tags are removed then.
Note – Within a text block to be colored using a textColor
tag, elements having a text font color already applied are not affected during runtime.
You can use textColor
tags nested into each other. Also, you can normally use textColor
tags within data bands and conditional blocks like in the following example.
Assume that you have the ColoredItem
class defined in your application as follows.
public class ColoredItem
{
public String Name { get { ... } }
public String Description { get { ... } }
public Color Color { get { ... } }
...
}
Given that items
is an enumeration of ColoredItem
instances, you can use the following template to output every item into a separate paragraph, which text is colored dynamically.
<<foreach [item in items]>><<textColor [item.Color]>><<[item.Name]>><</textColor>>
<</foreach>>
To output every item into a separate table row, which text is colored dynamically, you can use the following template.
«foreach [item in items]»«textColor [item.Color]»«[item.Name]» | «[item.Description]»«/textColor»«/foreach» |
---|
Note – Start and end textColor
tags can be located either in paragraphs of a single story (or table cell) or in rows of a single document table in the same way as foreach
tags.