Example T600080
Visible to All Users

Reporting for WPF - How to Register a Custom Page in the Report Wizard for the End-User Report Designer

This example demonstrates how to extend the Report Wizard in the End-User Report Designer with a custom page that allows you to edit the report page settings. This page is displayed after selecting the report type (for empty and data-bound reports).

Implementation Details

To accomplish this task, perform the following steps:

  1. Create the Presenter class as the DevExpress.Data.WizardFramework.WizardPageBase<TView, TModel> class descendant. Implement the logic to pass data between a Model and View, specify the next wizard page type, and define which page buttons should be available.
  2. Declare an interface that identifies the wizard page View.
  3. Create the ViewModel class as the DevExpress.Xpf.DataAccess.DataSourceWizard.WizardPageBase class descendant that implements the interface declared above. This ViewModel class processes data to display it in the User Interface.
  4. Write an XAML template with the ViewModel type referenced by a Key to define the page's visual appearance and layout. The specified Key is used to automatically locate the corresponding template.
    5. Create an XtraReportModel class descendant. Add custom fields to store the report page settings and override the Equals method to take into account the added fields.
  5. Override the existing ChooseReportTypePage to set the next page to your custom one.
  6. Implement the IWizardCustomizationService interface, which provides four methods for wizard customization. In this implementation, register the previously created Presenters, ViewModel, and Model, and write the logic to build a report.

Files to Review

More Examples

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

Example Code

CustomReportModel.cs(vb)
C#
using DevExpress.XtraReports.Wizards; using System.Drawing.Printing; namespace CustomReportWizard { class CustomReportModel : XtraReportModel { public PaperKind PaperKind { get; set; } public Margins PageMargins { get; set; } public CustomReportModel() { PaperKind = PaperKind.Letter; PageMargins = new Margins(100, 100, 100, 100); } public CustomReportModel(CustomReportModel model) : base(model) { PaperKind = model.PaperKind; PageMargins = new Margins(model.PageMargins.Left, model.PageMargins.Right, model.PageMargins.Top, model.PageMargins.Bottom); } public override object Clone() { return new CustomReportModel(this); } public override bool Equals(object obj) { var other = obj as CustomReportModel; return other != null && base.Equals(obj) && PaperKind == other.PaperKind && PageMargins == other.PageMargins; } public override int GetHashCode() { return base.GetHashCode() ^ PaperKind.GetHashCode() ^ PageMargins.GetHashCode(); } } }
ChoosePageSettingsPage.cs(vb)
C#
using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Drawing.Printing; using System.Linq; using DevExpress.Data.WizardFramework; using DevExpress.DataAccess.Wizard.Presenters; using DevExpress.Mvvm.DataAnnotations; using DevExpress.XtraReports.Wizards; namespace CustomReportWizard { class ChoosePageSettingsPage<TModel> : WizardPageBase<IChoosePageSettingsPageView, TModel>, IWizardPage<XtraReportModel> where TModel : CustomReportModel { XtraReportModel IWizardPage<XtraReportModel>.Model { get { return Model; } set { Model = (TModel)value; } } public ChoosePageSettingsPage(IChoosePageSettingsPageView view) : base(view) { } public override bool FinishEnabled { get { return Model.ReportType == ReportType.Empty; } } public override bool MoveNextEnabled { get { return Model.ReportType != ReportType.Empty; } } public override Type GetNextPageType() { return Model.ReportType == ReportType.Empty ? null : typeof(ChooseDataSourceTypePage<XtraReportModel>); } public override void Begin() { View.PaperKind = Model.PaperKind; View.Portrait = Model.Portrait; View.PageMargins = Model.PageMargins; } public override void Commit() { Model.PaperKind = View.PaperKind; Model.Portrait = View.Portrait; Model.PageMargins = View.PageMargins; } } interface IChoosePageSettingsPageView { PaperKind PaperKind { get; set; } bool Portrait { get; set; } Margins PageMargins { get; set; } } [POCOViewModel(ImplementIDataErrorInfo = true)] public class ChoosePageSettingsPageViewModel : DevExpress.Xpf.DataAccess.DataSourceWizard.WizardPageBase, IChoosePageSettingsPageView { public override string Description { get { return "Choose the required page settings."; } } public virtual IEnumerable<PaperKindViewInfo> AvailablePaperKinds {get; protected set;} public virtual PaperKindViewInfo SelectedPaperKind { get; set; } public virtual bool Portrait { get; set; } [Range(0,300)] public virtual int LeftMargin { get; set; } [Range(0, 300)] public virtual int RightMargin { get; set; } [Range(0, 300)] public virtual int TopMargin { get; set; } [Range(0, 300)] public virtual int BottomMargin { get; set; } PaperKind IChoosePageSettingsPageView.PaperKind { get { return (PaperKind)SelectedPaperKind.Id; } set { SetPaperKind(value); } } Margins IChoosePageSettingsPageView.PageMargins { get { return new Margins(LeftMargin, RightMargin, TopMargin, BottomMargin); } set { SetMargins(value); } } public ChoosePageSettingsPageViewModel() { var printerSettings = new PrinterSettings(); AvailablePaperKinds = printerSettings.PaperSizes.Cast<PaperSize>().Select(paperSize => { return new PaperKindViewInfo() { Id = (int)paperSize.Kind, DisplayName = paperSize.PaperName, SizeText = string.Format("{0}x{1}", paperSize.Width, paperSize.Height) }; }).ToArray(); } void SetPaperKind(PaperKind value) { var info = AvailablePaperKinds.SingleOrDefault(x => (PaperKind)x.Id == value) ?? AvailablePaperKinds.Single(x => (PaperKind)x.Id == PaperKind.Letter); SelectedPaperKind = info; } void SetMargins(Margins value) { LeftMargin = value.Left; RightMargin = value.Right; TopMargin = value.Top; BottomMargin = value.Bottom; } } }
CustomChooseReportTypePage.cs(vb)
C#
using System; using System.Collections.Generic; using DevExpress.DataAccess.Sql; using DevExpress.DataAccess.Wizard; using DevExpress.DataAccess.Wizard.Services; using DevExpress.Entity.ProjectModel; using DevExpress.XtraReports.Wizards; using DevExpress.XtraReports.Wizards.Presenters; using DevExpress.XtraReports.Wizards.Views; namespace CustomReportWizard { class CustomChooseReportTypePage : ChooseReportTypePage<XtraReportModel> { public CustomChooseReportTypePage(IChooseReportTypePageView view, IConnectionStorageService connectionStorageService, DataSourceTypes dataSourceTypes, IWizardRunnerContext context, ISolutionTypesProvider solutionTypesProvider) : base(view, connectionStorageService, dataSourceTypes, context, solutionTypesProvider) { } public override bool MoveNextEnabled { get { return true; } } public override Type GetNextPageType() { if(View.ReportType == ReportType.Standard || View.ReportType == ReportType.Empty) return typeof(ChoosePageSettingsPage<CustomReportModel>); return base.GetNextPageType(); } } }
WizardCustomizationService.cs(vb)
C#
using System; using DevExpress.DataAccess; using DevExpress.DataAccess.Wizard; using DevExpress.DataAccess.Wizard.Model; using DevExpress.Xpf.DataAccess.DataSourceWizard; using DevExpress.Xpf.Reports.UserDesigner.ReportWizard; using DevExpress.XtraReports.UI; using DevExpress.XtraReports.Wizards; using DevExpress.XtraReports.Wizards.Presenters; namespace CustomReportWizard { class WizardCustomizationService : IWizardCustomizationService { void IDataSourceWizardCustomizationService.CustomizeDataSourceWizard(DataSourceWizardCustomizationModel customization, ViewModelSourceIntegrityContainer container) { } void IWizardCustomizationService.CustomizeReportWizard(ReportWizardCustomizationModel customization, ViewModelSourceIntegrityContainer container) { customization.Model = new CustomReportModel(); container.RegisterType<ChoosePageSettingsPage<CustomReportModel>>(); container.RegisterType<ChooseReportTypePage<XtraReportModel>, CustomChooseReportTypePage>(); container.RegisterViewModel<IChoosePageSettingsPageView, ChoosePageSettingsPageViewModel>(); } bool IDataSourceWizardCustomizationService.TryCreateDataSource(IDataSourceModel model, out object dataSource, out string dataMember) { dataSource = null; dataMember = null; return false; } bool IWizardCustomizationService.TryCreateReport(XtraReportModel model, out XtraReport report) { var customModel = model as CustomReportModel; if(customModel == null || model.ReportType == ReportType.Template || model.ReportType == ReportType.Label) { report = null; return false; } IDataComponent dataSource = null; string dataMember = null; if(customModel.ReportType != ReportType.Empty) { var dataComponentCreator = new DataComponentCreator(); dataSource = dataComponentCreator.CreateDataComponent(model); dataMember = dataSource.DataMember; } var builder = new DevExpress.Xpf.Reports.UserDesigner.ReportWizard.ReportBuilder(dataSource, dataMember); report = new XtraReport(); report.PaperKind = customModel.PaperKind; report.Margins = customModel.PageMargins; builder.Build(report, customModel); return true; } } }

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.