简体   繁体   English

如何从FixedDocument中删除FixedPage?

[英]How to remove FixedPage from FixedDocument?

I am using a DocumentViewer to display a FixedDocument to the user before allowing the user to print or save the document. 我在允许用户打印或保存文档之前使用DocumentViewer向用户显示FixedDocument。 I have edited the DocumentViewer panel to have a checkbox that allows the user to select if they want a chart in the document or not. 我已经对DocumentViewer面板进行了编辑,以具有一个复选框,该复选框使用户可以选择是否要在文档中使用图表。

I am able to get the event of the checkbox being checked and its value but I cannot figure out a way to remove the chart from the FixedDocument and not leave a blank page at the end. 我能够检查到复选框及其值,但无法找出从FixedDocument中删除图表且最后不留空白页的方法。 I currently have it so that on the checkbox click I hide and show the Chart but again this leaves a blank page. 我目前拥有它,因此在复选框上单击“我隐藏并显示图表”,但这又留下了空白页。

if (value) BarChart.Visibility = Visibility.Visible;
else BarChart.Visibility = Visibility.Collapsed;

I have also tried rebuilding the FixedDocument on the checkbox event and use the checkbox value to decide whether or not to include the graph page. 我还尝试过在复选框事件上重建FixedDocument,并使用复选框值来确定是否包括图形页面。 The document renders fine the first time, then after unchecking the checkbox the chart page disappears, then when rechecking the checkbox the graph page shows up but the graph has no data (series are missing). 文档第一次呈现良好,然后取消选中复选框,图表页面消失,然后,当再次选中复选框时,图形页面显示出来,但是图形没有数据(序列丢失)。

Any ideas? 有任何想法吗?

Could this be a problem with the data binding of the chart or an issue with the FixedDocument? 这可能是图表的数据绑定有问题还是FixedDocument有问题?

Note: I am building the chart in the code behind and adding it like so: 注意:我正在后面的代码中构建图表,并像这样添加它:

// Add other pages to ReportDocument here

if (IncludeGraphPage)
{
    // Add graph page            
    PageContent ChartDocumentPageContent = new PageContent();
    FixedPage ChartDocumentPage = new FixedPage();
    ChartDocumentPage.Margin = new Thickness(20);                   
    ChartDocumentPage.Children.Add(BarChart);                
    ((IAddChild)ChartDocumentPageContent).AddChild(ChartDocumentPage);
    ReportDocument.Pages.Add(ChartDocumentPageContent); 
}

// Set the document viewer content
DocumentViewer.Document = ReportDocument;

I have checked out other SO questions but no solutions have worked for me yet. 我已经检查了其他SO问题,但是还没有解决方案对我有用。

I was able to figure out a way to rebuild the FixedDocument without making the chart series disappear. 我能够找到一种方法来重建FixedDocument,而又不会使图表系列消失。 The key was to add the chart as a VisualBrush like so: 关键是将图表添加为VisualBrush,如下所示:

VisualBrush chartBrush = new VisualBrush(BarChart) { Stretch = Stretch.Uniform };
Rectangle ChartRectangle = new Rectangle { Width = (1056-2*96), Height = (816 - 2*96), Fill = chartBrush };
ChartDocumentPage.Children.Add(ChartRectangle);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM