Back to Devexpress

DashboardControl.CustomExport Event

dashboard-devexpress-dot-dashboardwpf-dot-dashboardcontrol-5919af23.md

latest13.4 KB
Original Source

DashboardControl.CustomExport Event

Occurs before you save the exported document to the PDF and Image formats and allows you to customize the exported document.

Namespace : DevExpress.DashboardWpf

Assembly : DevExpress.Dashboard.v25.2.Wpf.dll

NuGet Package : DevExpress.Wpf.Dashboard

Declaration

csharp
public event CustomExportEventHandler CustomExport
vb
Public Event CustomExport As CustomExportEventHandler

Event Data

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

PropertyDescription
ExportActionGets the export action performed by an end-user. Inherited from CustomExportBaseEventArgs.
ExportModeGets the document export mode. Inherited from CustomExportBaseEventArgs.
ImageExportOptionsGets export options related to exporting a dashboard/dashboard item as an image. Inherited from CustomExportBaseEventArgs.
ItemComponentNameGets the component name of the exported dashboard item. Inherited from CustomExportBaseEventArgs.
PdfExportOptionsGets export options related to exporting a dashboard/dashboard item to PDF format. Inherited from CustomExportBaseEventArgs.
PrintPreviewOptionsGets options related to printing a dashboard/dashboard item using the Print Preview window. Inherited from CustomExportBaseEventArgs.
ReportGets the underlying report of the exported document.

The event data class exposes the following methods:

MethodDescription
GetChartContext(String)Returns chart context for the specified Chart dashboard item.
GetGaugeContext(String)Returns gauge export context for the specified Gauge dashboard item.
GetItemData(String)Returns multidimensional data for the specified dashboard item.
GetPrintableControl(String)Gets a printable control corresponding to the specified dashboard item.
GetPrintableControls()Gets printable controls corresponding to the exported dashboard items.

Remarks

The Dashboard Control raises the CustomExport event before saving the exported document to the PDF and Image formats. The event allows you to customize the exported document.

The following table illustrates dashboard items and their corresponding printable XRControls:

Dashboard ItemXRControl
ChartDashboardItemXRChart
ScatterChartDashboardItemXRChart
PieDashboardItemXRChart
PivotDashboardItemXRPivotGrid
RangeFilterDashboardItem (When CustomExportBaseEventArgs.ExportMode is SingleItem)XRChart
GaugeDashboardItemXRGaugeDashboardItem
TextBoxDashboardItemXRTextBox

Example

The following example shows how to customize dashboard items in the exported document when you handle the DashboardDesigner.CustomExport / DashboardViewer.CustomExport / DashboardControl.CustomExport events. You can use the CustomExportEventArgs.GetPrintableControls method to obtain the printable controls.

csharp
using DevExpress.DashboardCommon;
using DevExpress.DashboardExport;
using DevExpress.DashboardWin;
using DevExpress.XtraCharts;
using DevExpress.XtraGauges.Core.Drawing;
using DevExpress.XtraGauges.Win.Base;
using DevExpress.XtraGauges.Win.Gauges.Circular;
using DevExpress.XtraReports.UI;

private void DashboardControl_CustomExport(object sender, CustomExportEventArgs e) {
    foreach(var printControl in e.GetPrintableControls()) {
        if(printControl.Value is XRGaugeDashboardItem) {
            var gaugeItemName = printControl.Key;
            DashboardControl control = (DashboardControl)sender;
            var gaugeDashboardItem = control.Dashboard.Items[gaugeItemName] as GaugeDashboardItem;
            foreach(var dashGaugeElement in gaugeDashboardItem.Gauges) {
                foreach(var gaugePanel in 
                    e.GetGaugeContext(gaugeItemName).GetPrintableGauges(dashGaugeElement).Cast<XRDashboardGauge>()) {
                    if(gaugePanel != null) {
                        gaugePanel.MainSeriesLabel.ForeColor = Color.Red;
                    }
                }
            }
        }

        if(printControl.Value is XRChart) {
            var chartItemName = printControl.Key;
            DashboardControl control = (DashboardControl)sender;
            var chartDashboardItem = control.Dashboard.Items[chartItemName] as ChartDashboardItem;
            foreach(var pane in chartDashboardItem.Panes) {
                if(pane.Series.Count > 0) {
                    foreach(var dashSeries in pane.Series) {
                        if(dashSeries != null) {
                            var controlSeries = e.GetChartContext(chartItemName).GetControlSeries(dashSeries);
                            if(controlSeries != null) {
                                foreach(var ser in controlSeries) {
                                    LineSeriesView view = ser.View as LineSeriesView;
                                    if(view != null) {
                                        view.LineStyle.DashStyle = DashStyle.DashDot;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
vb
Imports DevExpress.DashboardCommon
Imports DevExpress.DashboardExport
Imports DevExpress.DashboardWin
Imports DevExpress.XtraCharts
Imports DevExpress.XtraGauges.Core.Drawing
Imports DevExpress.XtraGauges.Win.Base
Imports DevExpress.XtraGauges.Win.Gauges.Circular
Imports DevExpress.XtraReports.UI

Private Sub DashboardControl_CustomExport(ByVal sender As Object, ByVal e As CustomExportEventArgs)
    For Each printControl In e.GetPrintableControls()
        If TypeOf printControl.Value Is XRDashboardPanel Then
            Dim gaugeItemName = printControl.Key
            Dim designer As DashboardDesigner = CType(sender, DashboardDesigner)
            Dim gaugeDashboardItem = TryCast(designer.Dashboard.Items(gaugeItemName), GaugeDashboardItem)
            For Each dashGaugeElement In gaugeDashboardItem.Gauges
                For Each gaugePanel In e.GetGaugeContext(gaugeItemName).GetPrintableGauges(dashGaugeElement).Cast(Of XRDashboardGaugePanel)()
                    If gaugePanel IsNot Nothing Then
                        gaugePanel.MainSeriesLabel.ForeColor = Color.Red
                    End If
                Next gaugePanel
            Next dashGaugeElement
        End If

        If TypeOf printControl.Value Is XRChart Then
            Dim chartItemName = printControl.Key

            Dim designer As DashboardDesigner = CType(sender, DashboardDesigner)
            Dim chartDashboardItem = TryCast(designer.Dashboard.Items(chartItemName), ChartDashboardItem)

            For Each pane In chartDashboardItem.Panes
                If pane.Series.Count > 0 Then
                    For Each dashSeries In pane.Series
                        If dashSeries IsNot Nothing Then
                            Dim controlSeries = e.GetChartContext(chartItemName).GetControlSeries(dashSeries)
                            If controlSeries IsNot Nothing Then
                                For Each ser In controlSeries
                                    Dim view As LineSeriesView = TryCast(ser.View, LineSeriesView)
                                    If view IsNot Nothing Then
                                        view.LineStyle.DashStyle = DashStyle.DashDot
                                    End If
                                Next ser
                            End If
                        End If
                    Next dashSeries
                End If
            Next pane
        End If
    Next printControl
End Sub

The following code snippets (auto-collected from DevExpress Examples) contain references to the CustomExport 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.

dashboard-constant-lines/CS/ConstantLineExtension.WPF/ConstantLineModule.cs#L31

csharp
dashboardControl.ChartItemStyle = dashboardControl.Resources["chartStyle"] as Style;
dashboardControl.CustomExport += CustomExport;
dashboardControl.ConfigureItemDataCalculation += TargetDashboardControl_ConfigureItemDataCalculation;

wpf-dashboard-custom-properties/CS/Wpf-Dashboard-Custom-Properties/Modules/ChartItemModule/ChartItemModule.cs#L17

csharp
AssociatedObject.ChartItemStyle = resources["chartStyle"] as Style;
    AssociatedObject.CustomExport += DashboardControl_CustomExport;
}

wpf-dashboard-custom-properties/VB/Wpf-Dashboard-Custom-Properties/Modules/ChartItemModule/ChartItemModule.vb#L19

vb
AssociatedObject.ChartItemStyle = TryCast(resources("chartStyle"), Style)
    AddHandler AssociatedObject.CustomExport, AddressOf DashboardControl_CustomExport
End Sub

See Also

DashboardControl Class

DashboardControl Members

DevExpress.DashboardWpf Namespace