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:
- 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. - Declare an interface that identifies the wizard page View.
- 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. - Write an XAML template with the
ViewModel
type referenced by aKey
to define the page's visual appearance and layout. The specifiedKey
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 theEquals
method to take into account the added fields. - Override the existing ChooseReportTypePage to set the next page to your custom one.
- Implement the IWizardCustomizationService interface, which provides four methods for wizard customization. In this implementation, register the previously created
Presenters
,ViewModel
, andModel
, and write the logic to build a report.
Files to Review
- CustomReportModel.cs (VB:CustomReportModel.vb)
- ChoosePageSettingsPage.cs (VB:ChoosePageSettingsPage.vb)
- CustomChooseReportTypePage.cs (VB:CustomChooseReportTypePage.vb)
- WizardCustomizationService.cs (VB:WizardCustomizationService.vb)
More Examples
Does this example address your development requirements/objectives?
(you will be redirected to DevExpress.com to submit your response)
Example Code
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();
}
}
}
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;
}
}
}
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();
}
}
}
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;
}
}
}