private void CreateButtonClick(object sender, RoutedEventArgs e) { Logger.Write("Entering CreateButtonClick method"); var tab = TabControl.SelectedItem as TabItem; if (tab != null) { var reportProperty = tab.Content as UserControl; if (reportProperty != null) { // Create report IReport reportTemplate = null; IEnumerable <ReportItem> workItems = null; var selectedItem = TabControl.SelectedItem as TabItem; var project = projects[selectedItem]; reportTemplate = project.SelectedReport; simpleTracker.TrackEventAsync("Report", reportTemplate.Description); workItems = project.WorkItems; simpleTracker.TrackEventAsync("Workitems", workItems.Count().ToString()); var ms = new MemoryStream(); var pkg = Package.Open(ms, FileMode.Create, FileAccess.ReadWrite); var pack = string.Format("pack://{0}.xps", Guid.NewGuid()); PackageStore.AddPackage(new Uri(pack), pkg); var compressionOption = CompressionOption.NotCompressed; var document = new XpsDocument(pkg, compressionOption, pack); var report = reportTemplate.Create(workItems); var writer = XpsDocument.CreateXpsDocumentWriter(document); writer.Write(report.DocumentPaginator); // Create doc var doc = new DocumentViewer { Document = document.GetFixedDocumentSequence() }; // Remove toolbar from DocumentViewer var contentHost = doc.Template.FindName("PART_ContentHost", doc) as ScrollViewer; if (contentHost != null) { var grid = contentHost.Parent as Grid; if (grid != null) { grid.Children.RemoveAt(0); } } doc.FitToMaxPagesAcross(1); tab.Content = doc; TabSelectionChanged(null, null); } } }