private void btnPrint_Click(object sender, RoutedEventArgs e) { if (Popup != null && Popup.Content != null) { return; } //PrintDialog dialog = new PrintDialog(); //if (dialog.ShowDialog() == true) //{ Popup = new Popup(); FrameworkElement element = gridAnalysis.Parent as FrameworkElement; if (element != null) { Popup.Parent = element.Parent as FrameworkElement; if (Popup.Parent != null) { AnalysisViewer analysisViewer = new AnalysisViewer(); analysisViewer.Closed += analysisViewer_Closed; analysisViewer.DataContext = this.DataContext; analysisViewer.MaxWidth = 990; analysisViewer.Compute(); Popup.Content = analysisViewer; Popup.Show(); } } //DocumentPaginator paginator = new AnalysisPaginator(sp); //dialog.PrintDocument(paginator, "Analysis"); //} }
void analysisViewer_Closed(object sender, EventArgs e) { if (Popup != null && Popup.Content != null) { AnalysisViewer form = Popup.Content as AnalysisViewer; if (form != null) { form.Closed -= analysisViewer_Closed; } } //if (Popup.Content is AnalysisViewer) //{ // (Popup.Content as AnalysisViewer).Closed -= analysisViewer_Closed; //} Popup.Close(); Popup = null; }