MindFusion.Reporting for Silverlight Programmer's Guide
Custom Rendering of Report Elements

The term "rendering" is used to identify the process of creation of the report's visual appearance. A report is rendered when either RenderPage or RenderAllPages methods of a ReportLayout object are invoked. Both of these methods operate on an IRenderTarget object.

When a report is rendered, the items in the report are iterated and a visual representation is created for each item. This visual representation is represented by a Silverlight UIElement object, which is considered the root of the item's visual tree. After the item's visuals are created, the root UIElement object is passed to the Render method of the IRenderTarget object.

Customizing Rendering

After the item's visual representation is created but before it is passed to the Render method of the IRenderTarget object a special event is raised - Report.Prerender. This event enables clients to modify or completely replace the visual representation of the item before it is added to the final visual tree of the report. The event can also be used to prevent the rendering of an item.

Modifying Appearance

The root UIElement object defining the visual appearance of the item being rendered can be obtained from the RootVisual property of the PrerenderEventArgs object accompanying the Prerender event. The structure of the RootVisual depends on the type of the report item being rendered. The following table lists the structure of the RootVisual corresponding to different report items.

Report Item

RootVisual

CustomReportItem

<ContentControl />

ItemContainer

<Border />

Label

<Border>
    <TextBlock />
</Border>

Page

<Border />

Picture

<Border>
    <Image />
</Border>

PieChart

 

For example, to change the background of a Label, cast the RootVisual object to Border and set its Background.

Replacing Appearance

The RootVisual property can be set to any UIElement-derived object and this object will be used as appearance for the item. Note that the report layout is not affected by the size of the new RootVisual.

The following example demonstrates how to replace the appearance of all Label objects in a report with Silverlight Button elements. The example assumes that e is a reference to the PrerenderEventArgs passed to the event handler.

C#  Copy Code

if (e.Item is Label)
{
    var label = e.Item as Label;
    e.RootVisual = new Button()
    {
        Width = e.Size.Width,
        Height = e.Size.Height,
        Content = label.Text,
        Padding = new Thickness(0),
    };
}

Visual Basic  Copy Code

If TypeOf e.Item Is Label Then

    Dim label = CType(e.Item, Label)
    e.RootVisual = New Button() With _
    { _
        .Width = e.Size.Width, _
        .Height = e.Size.Height, _
        .Content = label.Text, _
        .Padding = New Thickness(0) _
    }

End If

Preventing Rendering

To prevent an item from appearing in the final report, set the SkipRender property of the accompanying PrerenderEventArgs to false. Hiding an item (as well as changing the size of the item's visual presentation) has no effect on the layout of the report.