As you may have heard, starting with version 10.1, we're introducing native report viewers for both WPF and Silverlight. The availability of these viewers enable you as a developer to target more platforms and reach a wider audience.
Using the report viewer, the reports can be easily imported into and displayed in a WinForms, ASP.NET, WPF and Silverlight application. And the best part is: They’ll all look exactly the same.
So while it’s possible to use the XtraReports Designer for Visual Studio to build reports in any project, the true portability and cross-platform compatibility of the product can not be demonstrated unless we create a report using the stand-alone End-User Reports Designer that ships with the XtraReports Suite.
Using the designer, we can create a report that is bound to data and all of its layout and configuration information is independent of the Visual Studio-based designer:
At this point, the report can be previewed within the designer, saved as a “repx” file and distributed to your end-users. Your end-users can further modify the report using the same designer, the Visual Studio designer, or load it into the client application that you’ve developed. For this example, I’ll focus on the WPF Report Viewer and show the simplest way to load and preview an existing “repx” report file.
To start, I’ve created a simple UI that can be used to load a repx file and display it in the WPF Report Viewer at runtime.
Switching to code view, I need to make sure that there is a using reference to the “DevExpress.Xpf.Printing” namespace:
1: using DevExpress.Xpf.Printing;
Finally, the following code uses the OpenFileDialog component to enable the user to browse for a repx file and loads it into the Report Viewer:
1: private void button1_Click(object sender, RoutedEventArgs e) {
2: Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog {
3: DefaultExt = ".repx", Filter = "XtraReport Layout (.repx)|*.repx" };
4:
5: if (dlg.ShowDialog() == true) {
6: textBox1.Text = dlg.FileName;
7: button2.IsEnabled = true;
8: }
9: }
10:
11: private void button2_Click(object sender, RoutedEventArgs e) {
12: DevExpress.XtraReports.UI.XtraReport report = new DevExpress.XtraReports.UI.XtraReport();
13: report.LoadLayout(textBox1.Text);
14: XtraReportPreviewModel model = new XtraReportPreviewModel(report);
15: DocumentPreviewWindow window = new DocumentPreviewWindow() { Model = model };
16: report.CreateDocument(false);
17: window.Show();
18: }
The report preview in WPF then looks like this:
