Posted 19 November 2019, 3:37 pm EST
I am trying to follow the example in the blog posting for ActiveReports 8 (https://www.grapecity.com/blogs/adding-exporting-functionality-to-wpf-viewer/) but there is no link to download the sample solution and the posted code seems to be missing some steps - no mention of how or where to define the “MainWindow.reportDocument”. I was able to get a little bit further when I found the forum posting here https://www.grapecity.com/forums/ar-dev/adding-exporting-to-wpf-vi. However, I am using version 12 not 7 and I also have it set up to where the user picks the report to load at runtime using a combobox and preview button.
My problems:
- how to I set the value for reportDocument?
- how do I get the “PdfCommand” name to exist in the namespace “clr-namespace:AXReports”
In my MainWindow.xaml.cs file I have the following:
using System;
using System.Windows;
using System.Windows.Controls;
namespace AXReports
{
/// <summary>
///
/// </summary>
public partial class MainWindow : Window
{
static readonly string CurrentFileLocation = AppDomain.CurrentDomain.BaseDirectory + @"\Reports\";
public static GrapeCity.ActiveReports.Document.PageDocument reportDocument { get; set; }
public MainWindow()
{
InitializeComponent();
}
/// <summary>
/// >Preview Button Click- Load selected report on click.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnPreview_Click(object sender, RoutedEventArgs e)
{
ComboBoxItem _report = (ComboBoxItem)CmbListBox.SelectedItem;
switch (_report.Content.ToString())
{
case "AXDocOverview.rdlx":
ReportViewer.LoadDocument(CurrentFileLocation + _report.Content);
break;
case "AXGlobalUDLSpec.rdlx":
ReportViewer.LoadDocument(CurrentFileLocation + _report.Content);
break;
case "AXAppSpecReview.rdlx":
ReportViewer.LoadDocument(CurrentFileLocation + _report.Content);
break;
case "AXAppSpecSign.rdlx":
ReportViewer.LoadDocument(CurrentFileLocation + _report.Content);
break;
case "AXUserAccessRequestBasic.rdlx":
ReportViewer.LoadDocument(CurrentFileLocation + _report.Content);
break;
case "AXUserAccessRequestAdobeSign.rdlx":
ReportViewer.LoadDocument(CurrentFileLocation + _report.Content);
break;
}
}
/// <summary>
///In the SelectionChanged event of the combo box, disable 'Preview' button, when no report is selected.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void CmbListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (CmbListBox.SelectedIndex == 0)
{
btnPreview.IsEnabled = false;
}
else
{
btnPreview.IsEnabled = true;
}
}
}
}
My PdfCommand.cs file has this:
using System;
using System.Windows;
using System.Windows.Input;
namespace AXReports
{
class PdfCommand : ICommand
{
public event EventHandler CanExecuteChanged;
public bool CanExecute(object parameter)
{
return true;
}
public void Execute(object parameter)
{
GrapeCity.ActiveReports.Export.Pdf.Section.PdfExport _exporter = new GrapeCity.ActiveReports.Export.Pdf.Section.PdfExport();
_exporter.Export(MainWindow.reportDocument, "..\\..\\Test.pdf");
MessageBox.Show("Exporting of Report to PDF Complete!");
}
}
}
My DefaultWPFViewerTemplates.xaml has this:
<ResourceDictionary ... xmlns:AXReports="clr-namespace:AXReports">
<AXReports:PdfCommand x:Key="PdfCommand" />
...
<!-- Custom buttons-->
<Button Command="{StaticResource PdfCommand}" ToolTip="Export to PDF" >
<StackPanel>
<Image Source="Image\\pdf.gif" />
</StackPanel>
</Button>
</ToolBar>