ComponentOne Reports for WinForms Designer Edition: ComponentOne Reports for WinForms > Working with C1PrintDocument > Styles > Calculated Style Properties

Calculated Style Properties

In the 2009 v3 release of Reports for WinForms, support was added for calculated style properties. For each style property, a matching string property was been added with the same name with "Expr" appended. For example, the BackColorExpr and TextColorExpr properties are matched to the BackColor and TextColor properties, and so on for all properties.

Sub-properties of complex properties (such as ImageAlign, Borders, and so on.)  also have matching expression sub-properties. For example, the LeftExpr property is matched to Left property and so on.

Style Expressions

The following objects can be used in style expressions:

      RenderObject: the current style's owner render object.

      Document: the current document.

      Page (and other page related objects such as PageNo): the page containing the object (but see note below).

      RenderFragment: the current fragment.

      Aggregates.

      Fields, DataBinding: reference the current data source; if the style's owner is within a table, and data sources have been specified for both rows and columns, this will reference the data source defined for the columns.

      RowNumber: row number in the associated data source.

      ColFields, ColDataBinding: only accessible if the style is used within a table, references the data source defined for the columns.

      RowFields, RowDataBinding: only accessible if the style is used within a table, references the data source defined for the rows.

Converted Types

When a calculated style property value is assigned to the real value that will be used to render the object, the types are converted according to the following rules:

      If the target property is numeric (int, float, and so on), the calculated value is converted to the required numeric type (converted from string, rounded, and so on) as necessary.

      If the target property is a Unit (for example, spacings), and the expression yields a number, the unit is created using the following constructor: new Unit(Document.DefaultUnitType, value). If the expression yields a string, that string is parsed using the normal Unit rules.

      In all other cases, an attempt is made to convert the value to the target type using the TypeConverter.

      Finally, if the expression yielded null, the parent style value is used as if the property has not been specified on the current style at all (such as the default behavior for unspecified style properties).

Page References

The following is an important note related to page references. Style expressions may reference the current page, for example:

ro.Style.BackColor = "iif(PageCount < 3, Color.Red, Color.Blue)";

Such expressions cannot be calculated when the document is generated. Thus, during generation such expressions are ignored (default values are used), and the values are only calculated when the actual page that contains the object is being rendered (for example, for drawing in the preview, exporting and so on).

As the result, style expressions that depend on pagination AND would affect the layout of the document may yield unexpected and undesirable results. For example, if the following expression is used for font size:

ro.Style.FontSize = "iif(PageCount < 3, 20, 30)";

The above expression would be ignored during generation, as the result the rendered text will most probably be too large for the calculated object's size and clipping will occur.


Send comments about this topic to ComponentOne.
Copyright © ComponentOne LLC. All rights reserved.