在我试图从我的前一个问题中打印的TreeView中,现在我转到父视图,我有一个如何包含TreeView的UserControl,它可以在我的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");静态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;
}我尝试了几乎所有的例子在类似的问题,但我得到的最好不过是的第一页的结果,如这。;(
我在使用WPF MVVM模式。这是正确的控制做它吗?或者我要去任何其他的WPF控件。
发布于 2015-01-01 06:13:29
解决这个问题的方法是在视图的FlowDocument部分中定义一个包含空表对象的*.xaml控件。然后,通过代码隐藏(即视图的*.xaml.cs部分),动态地将包含要打印的控件的块添加到*.xaml.cs中的表中。如果定义要在单独块中打印的每个UI元素,则表将在打印时自动执行分页。您将想出一种将SearchTreeView控件分解为更小控件的方法,这样它就不会只包含在一个块中。
有关表控件的更多信息,请参见此处:http://msdn.microsoft.com/en-us/library/ms747133%28v=vs.110%29.aspx
https://stackoverflow.com/questions/11396765
复制相似问题