123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- using FastReport;
- using FastReport.Utils;
- using System.Windows;
- namespace WpfDemo
- {
- public partial class DemoWindow : Window
- {
- private Report report;
- public string Version => Config.Version;
- public DemoReports DemoReports { get; }
- public DemoWindow()
- {
- InitializeComponent();
- // the designer will use embedded preview (same window as the designer)
- Config.DesignerSettings.EmbeddedPreview = true;
- // show how fast is FastReport
- Config.ReportSettings.ShowPerformance = true;
- // override these to not use standard progress form
- Config.ReportSettings.StartProgress += (s, e) => { };
- Config.ReportSettings.Progress += (s, e) => previewControl.ShowStatus(e.Message);
- Config.ReportSettings.FinishProgress += (s, e) => { };
- // warm up the Roslyn (used in net60 target)
- Config.CompilerWarmup();
- // these features are available in net6.0-windows target
- #if NETCOREAPP
- // do not compile a report if it has no user script (works faster)
- Config.CompilerSettings.ReflectionEmitCompiler = true;
- // use RoslynPad as a code editor
- FastReport.WPF.RoslynPad.SyntaxEditor.Register();
- #endif
- // shared folder for Map object
- FastReport.Map.MapObject.ShapefileFolder = Folders.MapsFolder;
- // populate reports list
- DemoReports = new DemoReports(Folders.ReportsFolder + "reports.xml");
- this.DataContext = DemoReports;
- this.Closing += (s, e) =>
- {
- if (previewControl.IsAsyncReportRunning)
- {
- // if async report is running, abort the report. Do not close the window
- previewControl.Report.Abort();
- e.Cancel = true;
- return;
- }
- DisposeReport();
- };
- }
- private void reportsTree_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
- {
- // previous report is not finished yet
- if (previewControl.IsAsyncReportRunning)
- return;
- var reportItem = reportsTree.SelectedItem as ReportItem;
- if (reportItem != null)
- {
- // in case we are in the UI layout phase, we need this call to be dispatched (case: expand the "Dialogs" category => Invalid Op exception)
- Dispatcher.BeginInvoke(() => RunReport(Folders.ReportsFolder + reportItem.FileName));
- }
- }
- private void RunReport(string fileName)
- {
- // dispose previous report
- DisposeReport();
- report = new Report();
- report.Load(fileName);
- SampleData.RegisterData(report);
- // show description
- description.SetDescription(report.ReportInfo.Description);
-
- // prepare report async way (you may use preview while report is preparing). A bit flickering though
- report.PrepareAsync(previewControl);
-
- // non-async way (prepare then show):
- //report.WpfPreview = previewControl;
- //report.Show();
- }
- private void DisposeReport()
- {
- // disposing a report may be necessary if it has dialog forms inside. These forms may prevent WPF app to close
- report?.Dispose();
- report = null;
- }
- }
- }
|