4

In a previous question I was trying to print from my TreeView, now i go to the parent view and I have hare an UserControl how contain an TreeView to display my search result on my WPFview, i tryed to print it and i surround with FlowDocumentScrollViewer as the code below:

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");

static printing.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;
    }

i tryed almost all the exmple in the Similar Questions but the best i got is just the first page of result like this.. ;(

I'm Using WPF MVVM pattern. Is this is the right control to do it?Or shall I go for any other WPF controls.?

4

1 回答 1

0

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

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

于 2015-01-01T06:13:29.340 回答