MindFusion.Reporting for Silverlight Programmer's Guide
Report Items

The following items are available to use in the MindFusion.Reporting for Silverlight reports. Report items share several common properties (derived from the base class ReportItem). The most important properties are Location and Size - specifying respectively the position and size of the item relative to its parent element. Other properties affecting the appearance of the item are Background, BorderBrush and BorderThickness.

Page

The page is the most fundamental element of a MindFusion.Reporting for Silverlight report. Pages in the report are represented by objects of the Page class. Each report can contain an arbitrary number of pages. The page itself can contain an arbitrary number of other report elements, such as labels and data ranges. When the report is processed by a call to its Run method, the pages can be split if the target space is insufficient to hold the processed page contents.

Properties

Pages have few properties of interest. Amongst them are the properties affecting the page appearance - Background, BorderBrush and BorderThickness. The Location property is irrelevant and is ignored. The Size property of pages only defines a design-time size. The actual page size depends on the parameters passed to the Layout method during report layout.

Header and Footer

Each page can optionally contain a header and/or a footer. Headers are displayed on top of the page, while footers are displayed at the bottom. If a page is split during report processing, its header and footer are displayed for each occurrence of the page in the final layout. Report Designer) or through XAML or code. The header and footer of a page are defined through DataTemplate objects, which are assigned to the HeaderTemplate and FooterTemplate properties of the page respectively. The root element of the data templates needs to be an ItemContainer object.

Here is an example of a page with a header and a footer declared in XAML:

XAML  Copy Code

<r:Page>

  <r:Page.HeaderTemplate>
    <DataTemplate>
      <r:ItemContainer Size="100%,45">
        <r:Label Text="This is the page header" Size="100%,45" Background="Orange"
          HorizontalAlignment="Center" VerticalAlignment="Bottom" />
      </r:ItemContainer>
    </DataTemplate>
  </r:Page.HeaderTemplate>

  <!-- Page content -->

  <r:Page.FooterTemplate>
    <DataTemplate>
      <r:ItemContainer Size="100%,45">
        <r:Label Text="This is the page footer" Size="100%,45" Background="Orange"
          HorizontalAlignment="Center" VerticalAlignment="Bottom" />
      </r:ItemContainer>
    </DataTemplate>
  </r:Page.FooterTemplate>

</r:Page>

There are various properties, such as BorderBrush, Background and Visible, which affect the visualization of the header and footer in the final layout.

Label

The label elements display texts within a report. Labels are represented by the Label class. The text displayed by the label can be either static, a value from a data source or a value calculated by an expression. Additionally, the text can contain various formatting specifiers, such as <b>, <i> and so on, which affect its appearance. The text displayed by a label is specified through its Text property.

Data-bound labels

Labels can be bound to values using ordinary Silverlight bindings. The DataContext of the label depends on the location of the label within the report. The DataContext of labels, placed in a data-bound DataRange object, are automatically initialized to corresponding object in the data range's data source when the DataRange is run. The DataContext of labels outside of a DataRange object is inherited from the label's parent element. The following XAML code demonstrates a label with text bound to the MyMember property of its DataContext.

XAML  Copy Code

<r:Label Text="{Binding MyMember}" />

Expressions

Labels can display texts more complex than static and bound values. You can include expressions within the text of the label. When the text is processed, the expressions within it are evaluated and replaced with the result of the evaluation. To embed expressions in the label text enclose the expressions in square brackets. For example, the following label text is valid and it will display the string "Date: " followed by the system's date at the time of evaluation. Note, that the expression in the example is highlighted in bold.

Expression  Copy Code

Date: [Now()]

The result of the evaluation of the above text will be something similar to "Date: 12/10/2008 2:23:38 PM".

It is possible to specify formatting to the value of the expression. To do so, add an '@' symbol after the expression but before the closing ']' then add the string representing the formatting specifier enclosed in quotes. The following example extends the previous one by adding formatting to the resulting date. Note, that the formatting specifier in the example is highlighted in bold.

Expression  Copy Code

Date: [Now()@"d"]

The result of the evaluation will now be similar to the following: "Date: 12/10/2008".

If you are using expressions in XAML, you might have to escape the quotes in the formatting specifier using &quot;:

Expression  Copy Code

<r:Label Text="Date: [Now()@&quot;d&quot;]" />

For more information about the expressions in MindFusion.Reporting for Silverlight in general, visit Expressions. For more information on how to use expressions in label texts, check Using Expressions in Label Texts.

Properties

The Text of the label is formatted using the string specified by the TextFormat property. Keep in mind that if the text evaluates to a string, the TextFormat property will have no effect on the output.

Other properties affecting the appearance of the label include FontFamily, FontSize, FontStyle and FontWeight, which affect the font of the displayed text; Background, BorderBrush and BorderThickness, which affect the border and background of the label; HorizontalAlignmentVerticalAlignment and Padding, which affect the positioning of the displayed text.

DataRange

The data range elements provide a way to implement master-detail relationships in MindFusion.Reporting for Silverlight reports. The data ranges are represented by the DataRange class. Extensive information about how to data-bind using data ranges can be found in the Supplying data for the Report topic.

Properties

DataRange objects inherit some common visualization properties, such as Background, BorderBrush and BorderThickness. There are three additional properties - AlternatingBackground, AlternatingBorderBrush and AlternatingBorderThickness, which default to null (Nothing in Visual Basic). When these properties are assigned values different from null, they are used as the background and border of even occurrences of this data range in the final layout. In other words, Background, BorderBrush an BorderThickness are used for the odd occurrences of a data range, while AlternatingBackground, AlternatingBorderBrush an AlternatingBorderThickness are used for the even ones.

The ArrangeByX property specifies whether to attempt to lay out data range instances horizontally first, then vertically. If ArrangeByX is set to false (the default), the instances of the data range are always arranged vertically regardless of whether there is space along the x-axis. The Repeat property is used with disconnected data ranges to specify the number of occurrences of these data ranges in the final layout.

Picture

The picture elements enable you to add static images to a report. Pictures are represented by the Picture class. Similarly to labels, pictures can be data-bound. The content of the picture is specified through the Image property.

Properties

The border and background of the image can be specified through the BorderBrush, BorderThickness and Background properties respectively. You can transform the image through the RenderTransform property. The alignment of the displayed image is controlled through the HorizontalAlignment and VerticalAlignment property.

CustomReportItem

Custom report items allow embedding of any Silverlight framework element in a MindFusion.Reporting for Silverlight report. The content of the custom report item is specified through its Template property. This property is of type DataTemplate, similarly to the ItemTemplate property of a DataRange. In contrast to the DataRange however, the root of the custom report item's template is not required to be ItemContainer.

In addition to the template, the custom items also provide a Value property, which can be used to associate particular object with the item. This object can be subsequently bound to from the elements contained in the template.

The following example demonstrates a very simple CustomReportItem, declared in XAML:

XAML  Copy Code

<r:CustomReportItem Value="5">
  <r:CustomReportItem.Template>
    <DataTemplate>
      <TextBlock Text="{Binding}" />
    </DataTemplate>
  </r:CustomReportItem.Template>
</r:CustomReportItem>

The report item above will simply display a Silverlight TextBlock with Text = "5". However, it illustrates the flexibility provided by the CustomReportItem class when creating MindFusion.Reporting for Silverlight reports.