【问题标题】:Printing AllPages with FlowDocumentScrollViewer使用 FlowDocumentScrollViewer 打印所有页面
【发布时间】:2012-07-09 14:11:11
【问题描述】:

previous question 中,我试图从我的 TreeView 打印,现在我转到父视图,我有一个 UserControl 如何包含 TreeView 以在我的 WPFview 上显示我的搜索结果,我尝试打印它,我用 FlowDocumentScrollViewer 包围如下代码:

view.xaml

<FlowDocumentScrollViewer x:Name="flow" Margin="10" BorderThickness="0">
<FlowDocument>
    <Section>
        <BlockUIContainer>
            <my:SearchTreeView Content="{Binding Stvm}"/>
        </BlockUIContainer>
    </Section>
</FlowDocument>

view.xaml.cs

 Printing.PrintDoc( flow.Document, txtSearch.Text + " - Result");

静态打印.cs

public static void PrintDoc(System.Windows.Documents.FlowDocument fd, string description)
    {
        double h, w, cw;            
        h = fd.PageHeight ;
        w = fd.PageWidth ;
        cw = fd.ColumnWidth;

        PrintDialog pd = new PrintDialog();
        //pd.PageRangeSelection = PageRangeSelection.AllPages;
        //pd.UserPageRangeEnabled = true;

        if (pd.ShowDialog() != true || fd == null) return;

        fd.PageHeight = pd.PrintableAreaHeight;
        fd.PageWidth = pd.PrintableAreaWidth;
        fd.PagePadding = new Thickness(50);
        fd.ColumnGap = 0;
        fd.ColumnWidth = pd.PrintableAreaWidth;

        System.Windows.Documents.IDocumentPaginatorSource dps  = fd;
      //  int c = dps.DocumentPaginator.PageCount;//0

        pd.PrintDocument(dps.DocumentPaginator, description);

        fd.PageHeight = h;
        fd.PageWidth = w;
        fd.PagePadding = new Thickness(0);
        fd.ColumnWidth = cw;
    }

我尝试了类似问题中的几乎所有示例,但我得到的最好结果只是结果的 首页,例如this.. ;(

我正在使用 WPF MVVM 模式。这是执行此操作的正确控件吗?或者我应该使用任何其他 WPF 控件吗?

【问题讨论】:

标签: wpf mvvm printing flowdocumentscrollviewer


【解决方案1】:

我解决此问题的方法是在我的视图的 *.xaml 部分中定义一个包含空 Table 对象的 FlowDocument 控件。然后,我通过代码隐藏(即视图的 *.xaml.cs 部分)将包含要打印的控件的块动态添加到 FlowDocument 中的表中。如果您在单独的 Block 中定义要打印的每个 UI 元素,表格将在打印时自动执行分页。您需要想办法将 SearchTreeView 控件分解为更小的控件,这样它就不会只包含在一个 Block 中。

有关表格控件的更多信息,请查看此处:http://msdn.microsoft.com/en-us/library/ms747133%28v=vs.110%29.aspx

【讨论】:

    猜你喜欢
    • 2012-01-11
    • 1970-01-01
    • 2011-07-07
    • 1970-01-01
    • 1970-01-01
    • 2011-09-22
    • 1970-01-01
    • 2018-01-06
    • 2011-01-06
    相关资源
    最近更新 更多