Back to Devexpress

SimpleLink.CreateDetail Event

wpf-devexpress-dot-xpf-dot-printing-dot-simplelink.md

latest8.2 KB
Original Source

SimpleLink.CreateDetail Event

Occurs every time the detail area of a SimpleLink is created.

Namespace : DevExpress.Xpf.Printing

Assembly : DevExpress.Xpf.Printing.v25.2.dll

NuGet Package : DevExpress.Wpf.Printing

Declaration

csharp
public event EventHandler<CreateAreaEventArgs> CreateDetail
vb
Public Event CreateDetail As EventHandler(Of CreateAreaEventArgs)

Event Data

The CreateDetail event's data class is CreateAreaEventArgs. The following properties provide information specific to this event:

PropertyDescription
DataGets or sets the object, which represents data for the area creation event.
DetailIndexGets or sets the index of a detail row for which the area creation event was called.

Remarks

The CreateDetail event is raised after the LinkBase.CreateDocument method is called for the SimpleLink object. This event is raised as many times as specified by the SimpleLink.DetailCount property value.

Handle the CreateDetail event to provide data for the detail area. An object containing data should be assigned to the CreateAreaEventArgs.Data property, and it will be represented using the template provided by the SimpleLink.DetailTemplate property.

Note

Do not pass visual objects (such as TextBox, Canvas, etc.) as detail area data, or the printing engine will not work as expected.

Example

This example demonstrates how to use SimpleLink to print data from a non-hierarchical datasource.

To do this, perform the following steps.

csharp
using System;
using System.Globalization;
using System.Windows;
using DevExpress.Xpf.Printing;
// ...
string[] data;

private void button1_Click(object sender, RoutedEventArgs e) {
    // Create an array of strings.
    data = CultureInfo.CurrentCulture.DateTimeFormat.DayNames;

    // Create a link and specify a template and detail count for it.
    SimpleLink link = new SimpleLink();
    link.DetailTemplate = (DataTemplate)Resources["dayNameTemplate"];
    link.DetailCount = data.Length;

    // Create a document.
    link.CreateDetail += new EventHandler<CreateAreaEventArgs>(link_CreateDetail);

    // Show a Print Preview window.
    PrintHelper.ShowPrintPreviewDialog(this, link);
}

void link_CreateDetail(object sender, CreateAreaEventArgs e) {
    e.Data = data[e.DetailIndex];
}
vb
Imports System
Imports System.Globalization
Imports System.Windows
Imports DevExpress.Xpf.Printing
' ...
Private data() As String

Private Sub button1_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
    ' Create an array of strings.
    data = CultureInfo.CurrentCulture.DateTimeFormat.DayNames

    ' Create a link and specify a template and detail count for it.
    Dim link As New SimpleLink()
    link.DetailTemplate = DirectCast(Resources("dayNameTemplate"), DataTemplate)
    link.DetailCount = data.Length

    ' Create a document.
    AddHandler link.CreateDetail, AddressOf link_CreateDetail

    ' Show a Print Preview window.
    PrintHelper.ShowPrintPreviewDialog(Me, link)
End Sub

Private Sub link_CreateDetail(ByVal sender As Object, ByVal e As CreateAreaEventArgs)
    e.Data = data(e.DetailIndex)
End Sub

The following code snippets (auto-collected from DevExpress Examples) contain references to the CreateDetail event.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

reporting-wpf-hide-specific-export-formats-from-the-document-preview-control/CS/HideExportFormats/MainWindow.xaml.cs#L35

csharp
};
link.CreateDetail += (s, args) => args.Data = data[args.DetailIndex];

reporting-wpf-documentpreviewcontrol-customize-toolbar/CS/MainWindow.xaml.cs#L22

csharp
};
link.CreateDetail += (s, e) => e.Data = data[e.DetailIndex];

reporting-wpf-print-listview-data/CS/Window1.xaml.cs#L23

csharp
link.DetailCount = listView1.Items.Count;
link.CreateDetail += new EventHandler<CreateAreaEventArgs>(link_CreateDetail);
link.CreateDocument(true);

reporting-wpf-hide-specific-export-formats-from-the-document-preview-control/VB/HideExportFormats/MainWindow.xaml.vb#L21

vb
link = New SimpleLink With {.DetailTemplate = CType(Resources("dayNameTemplate"), DataTemplate), .DetailCount = data.Length}
AddHandler link.CreateDetail, Sub(s, args) args.Data = data(args.DetailIndex)
Me.preview.DocumentSource = link

reporting-wpf-documentpreviewcontrol-customize-toolbar/VB/MainWindow.xaml.vb#L20

vb
link = New SimpleLink With {.DetailTemplate = CType(Resources("dayNameTemplate"), DataTemplate), .DetailCount = data.Length}
AddHandler link.CreateDetail, Sub(s, e) e.Data = data(e.DetailIndex)
Me.preview.DocumentSource = link

reporting-wpf-print-listview-data/VB/Window1.xaml.vb#L25

vb
link.DetailCount = Me.listView1.Items.Count
AddHandler link.CreateDetail, New EventHandler(Of CreateAreaEventArgs)(AddressOf link_CreateDetail)
link.CreateDocument(True)

See Also

DetailTemplate

SimpleLink Class

SimpleLink Members

DevExpress.Xpf.Printing Namespace