MindFusion.Reporting for Silverlight Programmer's Guide
Report Parameters

Report parameters have names, description and value. The value of a parameter can be any object, including expression.

Adding Report Parameters

Report parameters can be added to a report through the Parameters collection of the Report class. Parameters can be added either programmatically or through the built-in editor inside a designer.

Adding Parameters in Code

To add a parameter in code, create an instance of this class, specify its name, value, and optionally description and type (through the Name, Value, Description, and Type properties respectively), and add it to the Parameters collection. The type of a parameter is determined automatically from the value. However, setting the type explicitly is required when the parameter value is an expression. Otherwise, the value will be interpreted as string. The following code illustrates how to create a parameter with expression value in code:

C#  Copy Code

ReportParameter parameter = new ReportParameter("DateCreated", "[Now()]");
parameter.Type = ReportParameterType.Expression;
report.Parameters.Add(parameter);

Visual Basic  Copy Code

Dim parameter As New ReportParameter("DateCreated", "[Now()]")
parameter.Type = ReportParameterType.Expression
report.Parameters.Add(parameter)

Adding Parameters in XAML

To add a report parameter in XAML, use the following syntax:

XAML  Copy Code

<r:Report>
  <r:Report.Parameters>
    <r:ReportParameter Name="test" Value="5" Type="Double" />
    <r:ReportParameter Name="DateCreated" Value="[Now()]" Type="Expression" />
  </r:Report.Parameters>

  ...

</r:Report>

Accessing Report Parameters

Report parameters can be referenced in expressions by name. To access a report parameter, prefix its name with "Parameters." or "Report.". The following example demonstrates an expression that references the DateCreated parameter defined earlier:

Expression  Copy Code

The report was created on [Parameters.DateCreated.Value]

The Value member reference above is optional. Specifying [Parameters.DateCreated] will yield the same result. If the value of a parameter is an expression, it will be evaluated when the parameter is accessed.

The name, type or description of the parameter can be referenced using the same syntax. For example, the following expression displays the description of a parameter:

Expression  Copy Code

[Parameters.MyParam.Description]

If the value of the report parameter is a custom object, the properties of this object can be accessed in the same manner.

It is possible to reference report parameters within the value of other parameters. This needs to be done with caution to avoid cyclic referencing, which will result in an exception.